Hi there,
I have a list of dataframes (generated by reading multiple files) and all
dataframes are comparable in dimension and column names. They also have a
common column, which, I'd like to use for merging. To give a simple example of
what I have:
df1 - data.frame(c(LETTERS[1:5]),
What version of R are you using? I get this:
do.call(cbind, mylist)
df1.pos df1.data df2.pos df2.data df3.pos df3.data
1 A2 A6 A9
2 B6 B2 B3
3 C3 C9 C6
4 D
Gabor Grothendieck schrieb:
What version of R are you using?
R version 2.8.1 (2008-12-22) (running Windows)
I get this:
do.call(cbind, mylist)
df1.pos df1.data df2.pos df2.data df3.pos df3.data
1 A2 A6 A9
2 B6 B2
Try this also:
cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data,
names(data.frame(mylist)))])
On Wed, Jan 21, 2009 at 6:19 AM, Antje niederlein-rs...@yahoo.de wrote:
Hi there,
I have a list of dataframes (generated by reading multiple files) and all
dataframes are comparable in
Henrique Dallazuanna schrieb:
Try this also:
cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data,
names(data.frame(mylist)))])
Hi Henrique,
cool solution - that's seems to be the easiest way!
though I thought there should be some possibiliy of multiple merge
Anyway, this will do it
Hi Antje,
Try this:
merge(merge(mylist[[1]], mylist[[2]], by = pos), mylist[[3]])
On Wed, Jan 21, 2009 at 11:19 AM, Antje niederlein-rs...@yahoo.de wrote:
Henrique Dallazuanna schrieb:
Try this also:
cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data,
names(data.frame(mylist)))])
merge.zoo can do a multiple merge. We create a list of
zoo objects, mylist.z, and then perform the merge:
library(zoo)
mylist.z - lapply(mylist, function(x) zoo(x$data, as.character(x$pos)))
do.call(merge.zoo, mylist.z)
df1 df2 df3
A 2 6 9
B 6 2 3
C 3 9 6
D 1 7 2
E
Another possibility is Reduce:
Reduce(function(x,y,by='pos')merge(x,y,by='pos'),mylist)
pos data.x data.y data
1 A 2 69
2 B 6 23
3 C 3 96
4 D 1 72
5 E 9 51
- Phil Spector
8 matches
Mail list logo