[R] Programming chalange

milicic.marko milicic.marko at gmail.com
Fri Sep 26 01:30:02 CEST 2008


Okay... I would like to have some elegant (writting generic R code)
solution to do following.

I have a dataset

X1 X2 X3 X4
1  2    3  4
1  2    3  4
1  2    3  4
1  2    3  4
1  2    3  4
1  2    3  4
1  2    3  4
1  2    3  4


I would like to specify sometnig like this:

windows <- c(3, 4);
functions <- c(min, max);
columns <- c(X1, X2);


and to get resulting data frame with following columns....

X1, X2, X3, X4, minX1(previous 3 obs.), minX1(previous 4 obs.),
minX2(previous 3 obs.), minX2(previous 4 obs.),
maxX1(previous 3 obs.), maxX1(previous 4 obs.), maxX2(previous 3
obs.), maxX2(previous 4 obs.)


I'm guessing that it should be based on apply function...


Thnaks



More information about the R-help mailing list