[R] understanding time series objects

Angel angel_lul at hotmail.com
Fri Aug 8 12:46:56 CEST 2003


### First, is there a way to access a univariate time series as a matrix
instead of a vector?
# For example:
data(UKLungDeaths)
# If I do
apply(mdeaths,1,cumsum)
# Gives an error as mdeaths is not a matrix but a vector, although when I
look at it :
mdeaths
# the ts object has a matrix like "appearance"
# The only way of doing it I've found is:
mdeaths2<-as.matrix(mdeaths)
dim(mdeaths2)<-c(12,6)
mdeaths2<-apply(mdeaths2,2,cumsum)
mdeaths[]<-mdeaths2
# It is not very efficient to solve the problem of applying a cummulative
sum to each year

### Second, for a multivariate ts:
data(UKLungDeaths)
Multits<-ts.union(mdeaths, fdeaths)
# Why does
Multits$mdeaths
# not work and I have to use:
Multits[,"mdeaths"]
# Is it the way it works or am I missing something?
# Thanks as always,
# Angel




More information about the R-help mailing list