[R] Merging data.frames
Tony Plate
tplate at blackmesacapital.com
Fri Nov 8 23:34:23 CET 2002
> d1 <- data.frame(val1=c(A=1,B=3,C=5),val2=c(2,4,6))
> d1
val1 val2
A 1 2
B 3 4
C 5 6
> d2 <- data.frame(val3=c(A=1,C=2,D=3),val4=c(4,5,6))
> d2
val3 val4
A 1 4
C 2 5
D 3 6
> merge(d1, d2, by="row.names")
Row.names val1 val2 val3 val4
1 A 1 2 1 4
2 C 5 6 2 5
>
At 04:05 PM 11/8/2002 -0500, Paul Boutros <pcboutro at engmail.uwaterloo.ca>
wrote:
>Is it possible to combine two data-frames, just taking the rows where
>these frames have equivalent names?
>So for example I would want to take:
>
>d1:
> val1 val2
>A 1 2
>B 3 4
>C 5 6
>
>and d2:
> val3 val4
>A 1 4
>C 2 5
>D 3 6
>
>to merge into:
> val1 val2 val3 val4
>A 1 2 1 4
>C 5 6 2 5
>
>Is this kind of "merge on equal rows" to create a subset of the two
>data-frames possible in R, or would I need to move to an altnerate
>lagnauge to do this?
>
>Thanks for any ideas!
>Paul
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
>Send "info", "help", or "[un]subscribe"
>(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-- solution found after a lengthy and arduous perusal of the
difficult-to-locate documentation for the merge function :-)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list