[R] apply fn to many dataframes

James Fearon jfearon at stanford.edu
Tue May 26 00:19:58 CEST 2009


Hi,

Say I have dataframes d1, d2, ... , dn, and I want to apply a 
function to all of them.  For example, say I want to change the name 
of the second variable in each dataframe to "x2".  The following doesn't work:

a = list(d1,d2,d3,d4)
lapply(a,function(x) names(x)[2] = "x2")

What would work?

Thanks for any help.




More information about the R-help mailing list