[R] merge with origin information in new variable names
eric.fail at gmx.com
Sun Apr 24 23:21:19 CEST 2011
Here is my simple question,
I have n data frames that I would like to merge, but I can't figure
out how to add information about the origin of the variable(s).
Here is my problem,
DF.wave.1 <- data.frame(id=1:10,var.A=sample(letters[1:4],10,TRUE))
DF.wave.2 <- data.frame(id=1:10,var.M=sample(letters[5:8],10,TRUE))
DF.wave.3 <- data.frame(id=1:10,var.A=sample(letters[5:8],10,TRUE))
Now; I would like to merge the three dataframes into one, but append a
suffix to the individual variables names about thir origin.
DF.wave.all <- merge(DF.wave.1,DF.wave.2,DF.wave.3,by="id", [what to do here])
In other words, I would like it to loook like this.
id var.A.wave.1 var.M.wave.2 var.A.wave.3
1 1 c h j
2 2 c e j
3 3 c g k
4 4 c e j
5 5 c g i
6 6 d e k
7 7 c h k
8 8 b g j
9 9 b f i
10 10 d h i
Is there a command I can use directly in merge? 'suffixes' isn't
really handy here.
More information about the R-help