Rui Rui - 1 month ago 12
R Question

merge columns of two dataframes

How can two dataframes be quickly merged?
dataframes

df1<-data.frame(a=(1:5),b=(1:5))
df2<-data.frame(c=(1:5),d=(1:5))


intended output:

output<-data.frame(a=(1:5),b=(1:5),c=(1:5),d=(1:5))

Answer

You can try this by using other function like

cbind.data.frame(df1,df2)
  a b c d
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5

or

cbind2(df1,df2)
  a b c d
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5