Re: [R] Time series indexes

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 27 Apr 2005 - 22:48:12 EST

On 4/26/05, Fernando Saldanha <fsaldan1@gmail.com> wrote:
>
> I tried to assign values to specific elements of a time series and got
> in trouble. The code below should be almost self-explanatory. I wanted
> to assign 0 to the first element of x, but instead I assigned zero to
> the second element of x, which is not what I wanted. Is there a
> function that will allow me to do this without going into index
> arithmetic (which would be prone to errors)?
>
> FS
>
> > x<- ts(c(1,2,3,4), start = 2)
> > x
> Time Series:
> Start = 2
> End = 5
> Frequency = 1
> [1] 1 2 3 4
> > x[2] <- 0
> > x
> Time Series:
> Start = 2
> End = 5
> Frequency = 1
> [1] 1 0 3 4

 Any of the following will do it:
 x[1] <- 0
 # or
 window(x, start = 2, end = 2) <- 0
 # or since time 2 is at the beginning:
 window(x, end = 2) <- 0

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Apr 27 22:52:18 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:27 EST