[R] Create matrices for time series

mathijsdevaan mathijsdevaan at gmail.com
Thu Apr 14 09:51:55 CEST 2011


Hi list, I would like to use the following data.frame to generate matrices
over a 3 year moving window:

DF = data.frame(read.table(textConnection("  A  B  C
80  8025  1995
80  8026  1995
80  8029  1995
81  8026  1996
82  8025  1997
82  8026  1997
83  8025  1997
83  8027  1997
84  8026  1999
84  8027  1999
85  8028  1995
85  8029  1998"),head=TRUE,stringsAsFactors=FALSE))

Function to be applied: t(as.matrix(table(DF[,1:2]))) %*%
as.matrix(table(DF[,1:2]))

I tried this without success:
n<-rollapply(DF, width = 3, FUN = t(as.matrix(table(DF[,1:2]))) %*%
as.matrix(table(DF[,1:2])), align = "right")

Any suggestions? Thanks a lot!

--
View this message in context: http://r.789695.n4.nabble.com/Create-matrices-for-time-series-tp3449005p3449005.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list