Re: [R] recursive function

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

Hi!

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

df1<-df
df1[[1]]<-paste("R",df[[1]],sep="_")
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

  SERIES YEAR value

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,
Kimmo

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive