Skip to content

Merge 10 data frames with 3 id columns that are common to all data frames

5 messages · Baptiste Auguie, Pele

#
Hi,

Try this:
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:

            
_____________________________

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
#
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:

  
    
#
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,
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:

            
_____________________________

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
#
Perfect - many thanks!!!
baptiste auguie-2 wrote: