Ernesto Jardim
2003-Mar-20 15:09 UTC
[R] dataframes (The message that once had a suspicious header)
Hi I want to combine 2 dataframes (t1 and t2) in order to get a third one (t3). The dataframes are below. In SQL I would do something like: SELECT t1.f1,t1.f2,t1.f3,t2.f4 FROM t1, t2 WHERE t1.f1=t2.f1 AND t1.f2=t2.f2 How can I do it with R ? Thanks EJ> t1f1 f2 f3 1 A C E1 2 A D E2 3 B C E3 4 B D E4> t2f1 f2 f4 1 A C F1 2 A C F2 3 B C F3 4 B C F4 5 A D F5 6 A D F6> t3f1 f2 f3 f4 1 A C E1 F1 2 A C E1 F2 3 B C E3 F3 4 B C E3 F4 5 A D E2 F5 6 A D E2 F6
Peter Wolf
2003-Mar-20 16:23 UTC
[R] dataframes (The message that once had a suspicious header)
Ernesto Jardim wrote:> Hi > > I want to combine 2 dataframes (t1 and t2) in order to get a third one > (t3). The dataframes are below. > > In SQL I would do something like: > > SELECT t1.f1,t1.f2,t1.f3,t2.f4 FROM t1, t2 > WHERE t1.f1=t2.f1 AND t1.f2=t2.f2 > > How can I do it with R ? > > Thanks > > EJ > > > t1 > f1 f2 f3 > 1 A C E1 > 2 A D E2 > 3 B C E3 > 4 B D E4 > > t2 > f1 f2 f4 > 1 A C F1 > 2 A C F2 > 3 B C F3 > 4 B C F4 > 5 A D F5 > 6 A D F6 > > t3 > f1 f2 f3 f4 > 1 A C E1 F1 > 2 A C E1 F2 > 3 B C E3 F3 > 4 B C E3 F4 > 5 A D E2 F5 > 6 A D E2 F6 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpTry function "merge". For details see: help(merge)> t1[,1] [,2] [,3] [1,] "A" "C" "E1" [2,] "A" "D" "E2" [3,] "B" "C" "E3" [4,] "B" "D" "E4"> t2[,1] [,2] [,3] [1,] "A" "C" "F1" [2,] "A" "C" "F2" [3,] "B" "C" "F3" [4,] "B" "C" "F4" [5,] "A" "D" "F5" [6,] "A" "D" "F6"> merge(t1,t2,1:2)V1 V2 V3.x V3.y 1 A C E1 F1 2 A C E1 F2 3 A D E2 F5 4 A D E2 F6 5 B C E3 F3 6 B C E3 F4 --- Peter Wolf