jacky_learns_to_code jacky_learns_to_code - 17 days ago 4
R Question

How to merge columns of one file to another file in R?

Suppose I have two files

df1.csv
and
df2.csv
:

a b c
1 . . .
2 . . .
3 . . .


and

d e f
1 . . .
2 . . .
3 . . .


How can I merge both
.csv
to be the following output?

a b c d e f
1 . . . . . .
2 . . . . . .
3 . . . . . .

Answer

Akrun solution does work:

df1 <- structure(list(a = c(1L, 1L, 1L), b = c(2L, 2L, 2L), c = c(3L, 3L, 3L)),
                 .Names = c("a", "b", "c"), class = "data.frame", row.names = c(NA,-3L))


df2 <- structure(list(a = c(1L, 1L, 1L), b = c(2L, 2L, 2L), c = c(3L, 3L, 3L)),
                 .Names = c("d", "e", "f"), class = "data.frame", row.names = c(NA,-3L))

cbind(df1, df2)    

 a b c d e f
 1 2 3 1 2 3
 1 2 3 1 2 3
 1 2 3 1 2 3