[R] Merge 10 data frames with 3 id columns that are common to all data frames
Pele
drdionc at yahoo.com
Mon Mar 9 01:15:56 CET 2009
Perfect - many thanks!!!
baptiste auguie-2 wrote:
>
> The function expects a list of data.frames as a first argument but you
> provided a data.frame instead, the others are interpreted as optional
> arguments to merge_recurse(). Try this instead,
>
>> merge_recurse(list(DF1,DF2,DF3,DF4))
>
>
> var1 x y t u d e f o
> 1 a 1.39679 2 -1.18377 2 -0.041194 31 -1.05526 11
> 2 b -0.20453 2 0.22777 2 -0.543270 31 1.45777 11
> 3 c -0.91446 2 -0.97843 2 -1.279132 31 1.88759 11
> 4 d -1.18069 2 -0.23963 2 -0.064799 31 -0.85747 11
> 5 e -1.24802 2 1.43072 2 0.183317 31 2.50352 11
>
>
> HTH,
>
> baptiste
>
> On 8 Mar 2009, at 23:40, Pele wrote:
>
>>
>> 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.
>>
>> ______________________________________________
>> 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-tp22402493p22404961.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list