Re: [R] recursive function

From: K. Elo <>
Date: Mon, 14 Jun 2010 20:56:13 +0300


Do you mean something like this (df is your original data frame):

colnames(df1)<-c("SERIES","YEAR","value") df1$value[ df1$YEAR==2009 ]<-5
for (i in c(2009:2007)) { df1$value[ df1$YEAR==(i-1) ]<-( df1$value[ df1$YEAR==i ]-df$DELTA[ df$year==i ] ) }

Now the output:

> df1


1 R_EC01 2006   -19
2 R_EC01 2007    -9
3 R_EC01 2008    -4
4 R_EC01 2009     5

Please let me know if you were looking for a more general approach suitable for larger data frames with e.g. several "variable" classes (EC01, EC02 etc.)

Kind regards,

University of Turku, Finland
Dep. of Political Science and Contemporary history

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 14 Jun 2010 - 17:59:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Jun 2010 - 18:40:30 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive