Skip to content
Prev 318336 / 398502 Next

combining 2 dataframes into a 3rd df, with 1 row for each row in df1 & df2

df1 <- data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )

df2 <- data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1
,dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )

I figured it out.
mydf <- merge(df2,df1,all.y=T, all.x=T)
mydf2 <- mydf[,sort(names(mydf))]
On Tue, Feb 26, 2013 at 8:34 AM, Anika Masters <anika.masters at gmail.com> wrote: