[R] Merge 10 data frames with 3 id columns that are common to all data frames
Pele
drdionc at yahoo.com
Mon Mar 9 00:40:05 CET 2009
I tried using merge_all as shown below but I am getting an error ... can
anyone tell me what I am doing wrong? The result table below is what I am
looking for.
DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
DF2 <- data.frame(var1 = letters[1:5], t = rnorm(5), u =2)
DF3 <- data.frame(var1 = letters[1:5], d = rnorm(5), e =31)
DF4 <- data.frame(var1 = letters[1:5], f = rnorm(5), o =11)
DF_all <- merge_all(DF1, DF2, DF3, DF4, by="var1" )
Error in fix.by(by.x, x) :
'by' must specify column(s) as numbers, names or logical
Results I would like
var1 x y d e t u x
a -1.725155 2 -0.48097 31 0.032968 2 -1.725155
b 0.799983 2 2.32965 31 -0.385364 2 0.799983
c -1.387224 2 0.61761 31 0.977404 2 -1.387224
d 0.645946 2 0.46152 31 1.334591 2 0.645946
e 0.058783 2 -0.25312 31 0.631676 2 0.058783
baptiste auguie-2 wrote:
>
> Hi,
>
> Try this:
>
>> DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
>> DF2 <- data.frame(var1 = letters[3:7], x = rnorm(5), y=3)
>> DF3 <- data.frame(var1 = letters[6:10], x = rnorm(5), y=0)
>> # ... DF10 if you wish
>>
>> ( result <- merge_all(list(DF1, DF2, DF3) ))
>>
>> save( result, file ="merged.rda")
>
> I didn't know of this function, thanks. Similar solutions using base
> functions were proposed recently on
> http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge
> and i've now added this for reference.
>
> baptiste
>
> On 8 Mar 2009, at 20:23, Pele wrote:
>
>>
>> Hi R users,
>>
>> Can anyone share some example code using merge_all (from the reshape
>> package) to merge 10 data frames into 1 file.
>>
>> Thanks in advance for any help!
>> --
>> View this message in context:
>> http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>
> _____________________________
>
> Baptiste Auguié
>
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
>
> Phone: +44 1392 264187
>
> http://newton.ex.ac.uk/research/emag
>
> ______________________________________________
> 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.
>
>
--
View this message in context: http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22404595.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list