Liaw, Andy
2006-Feb-22 18:23 UTC
[R] Merge dataframes with no shared rows, some shared and som e unshared columns
> first <- data.frame(a=1:3, b=4:6) > second <- data.frame(b=7:9, c=10:12) > third <- merge(first, second, by="b", all=TRUE) > thirdb a c 1 4 1 NA 2 5 2 NA 3 6 3 NA 4 7 NA 10 5 8 NA 11 6 9 NA 12 It's easy to replace the Nas with whatever value you want. No, merge() does not work with more than two data sets at a time. Andy From: mtb954 at gmail.com> > Dear R-users, > > I have two dataframes FIRST and SECOND that do not share any rows > (i.e., there is no unique identifier linking the rows in the two > dataframes, the rows are independent). > > The dataframes have three variables (in columns) in common, but each > dataframe also has some variables not shared by the other. > > I wish to merge FIRST and SECOND into a THIRD dataframe, stacking the > shared columns and including the unshared columns from FIRST and > SECOND as columns in THIRD. Also, I wish rows in THIRD that do not > have a value in a particular column (because they came from a > dataframe without that column) to acquire the value "0" (zero). > > Finally, it it possible to merge >2 dataframes using the > merge function? > > Any ideas? Thanks, Mark > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Seemingly Similar Threads
- Merge two dataframes of different column length and row length by two columns at a time
- [Bug 3186] New: Surprisingly large unshared memory usage
- Out of Office: Out of Office: Out of Office: Ou t of Office: Ou t of Office: Ou t of Office: Ou t of Office: Ou t of Office: Ou t of Office: Ou t of Office: Re : som e kind of t i meou t problem in pbx _sp ool.c
- merging multiple columns from two dataframes
- R merge two dataframes with different row?