0

I am doing this in R I have 2 dataframes A & B. A has 9 columns, while B has 8 columns which are in common. A consist of unique ID 1-500, while B consist of unique ID 501-1100.

I need to combine both the tables.

Please help me with the command. It would be great if multiple possible commands are told.

Jatin
  • 25
  • 4
  • Welcome to StackOverflow! It would be very helpful if you can provide an example of your data. Please look into `dput` or providing a reprex: https://stackoverflow.com/help/minimal-reproducible-example. Edit: You're probably looking for `join` or `merge`. – Matt Apr 04 '20 at 17:21
  • Does this answer your question? [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) – dc37 Apr 04 '20 at 17:23

2 Answers2

1

I would try to add a vector as a column with missing values to B and then just bind both datframes by rows:

empty<-c(NA * nrow(B))
cbind(B, empty)

rbind(A, B)
Jeni
  • 918
  • 7
  • 19
0

This can be accomplished in multiple ways using base functions and other packages:

You could try merge:

merge(x, y, by, by.x, by.y, sort = TRUE)

Dplyr:

And data.table. Example here.

DSH
  • 1,038
  • 16
  • 27