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

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Apr 13 18:25:49 CEST 2005


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