[R] Behavior of apply() when used with start()

Fernando Saldanha fsaldan1 at gmail.com
Wed Apr 13 19:37:53 CEST 2005


Maybe one person can, but I am not sure who is that person.

When I called 

starts2 <- apply(arr, 2, start)

I was not asking for the attibutes of the whole matrix. 

It rather seems to me that cbind() is the culprit. When it copies the
time series tsa and tsb it seems to reset their start attributes to 1.

In any case, I did what I wanted to do by using list() instead of
cbind() and lapply() instead of apply().

FS


On 4/13/05, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Wed, 13 Apr 2005, Fernando Saldanha wrote:
> 
> > Can someone explain why starts1 and starts2 are diffferent in the example below?
> 
> Yes, at least one person can.  Actually, anyone who looked could:
> 
> > arr
> Time Series:
> Start = 1
> End = 3
> Frequency = 1
>    tsa tsb
> 1   1  NA
> 2   2   2
> 3   3   3
> 
> Note the times series attributes apply to the whole matrix.
> 
> > After running this program
> >
> > a <- c(1:3)
> > b <- c(2:3)
> > tsa <- ts(a)
> > tsb <- ts(b, start = 2)
> > arr <- cbind(tsa, tsb)
> > starts1 <- cbind(start(tsa), start(tsb))
> > starts2 <- apply(arr, 2, start)
> >
> > I get:
> >
> >> starts1
> >     [,1] [,2]
> > [1,]    1    2
> > [2,]    1    1
> >
> >> starts2
> >     tsa tsb
> > [1,]   1   1
> > [2,]   1   1
> 
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>




More information about the R-help mailing list