0

I have 2 data frames D1 and D2. dim(D1) = 6096 x 2 dim(D2) = 6100 x 5 I would like to connect D1 and D2 such that we have both the two columns of D2 followed by both the 4 columns of D2 on the right. And, 4 rows of first two columns (D1) have NA's or Null or 0 values. I'm looking for a function. Many questions on stacks overflow are where both data frames are added to each other either by rows or column. I don't want to add their values.

Imagine dataframes df1 and df2 and the output is dfinal.

df1 = data.frame(rep(c(1,3,5,7), 2))
df2 = data.frame(rep(c(2,4,6,8), 2))
df1 = cbind(df1,df2)
colnames(df1) = c("C1","C2")
df3 = data.frame(rep(c("1","b","c"), 2))
df4 = data.frame(rep(c("d","3","f"), 2))
df5 = data.frame(rep(c("g","h","2"), 2))
df2 = cbind(df3,df4,df5)
colnames(df2) = c("C3","C4","C5")
df2 = rbind(df2, NA)
df2 = rbind(df2, NA)
dfinal = cbind(df1,df2)
Czar.Wolfgang
  • 67
  • 2
  • 3
  • 12
  • 1
    https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right – Chabo May 30 '18 at 20:19
  • 1
    Possible duplicate of [How to join (merge) data frames (inner, outer, left, right)?](https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right) – Chabo May 30 '18 at 20:20
  • No, that's not the solution. There are many questions that mislead to think that my and their question is the same. – Czar.Wolfgang May 30 '18 at 20:35
  • 1
    What about this one https://stackoverflow.com/questions/3699405/how-to-cbind-or-rbind-different-lengths-vectors-without-repeating-the-elements-o – TBT8 May 30 '18 at 20:51
  • 2
    Please illustrate with sample data that mimics your structure: [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Parfait May 30 '18 at 21:07
  • I have uploaded the code and instructions. Thanks! – Czar.Wolfgang May 31 '18 at 18:10

0 Answers0