0

I am trying to merge two relatively similair dataset without much success. For me rbind() or left_join() aren't working. My begindatasets are:

A:

ID item1 item2 item3
1 5 0 0
2 0 0 0
3 0 2 0
4 0 0 3
5 0 3 4
6 4 0 0

and B:

ID item1 item6 item10
7 2 0 0
8 0 0 4
9 2 2 5
10 0 0 3
11 0 3 4
12 1 1 0

I want to combine these to result in C:

ID item1 item2 item3 item6 item10
1 5 0 0 NA NA
2 0 0 0 NA NA
3 0 2 0 NA NA
4 0 0 3 NA NA
5 0 3 4 NA NA
6 4 0 0 NA NA
7 2 NA NA 0 0
8 0 NA NA 0 4
9 2 NA NA 2 5
10 0 NA NA 0 3
11 0 NA NA 3 4
12 1 NA NA 1 0
Jeroen
  • 1
  • 1
  • 1
    `merge(A, B, all = TRUE)` – Ronak Shah Jan 08 '20 at 11:06
  • You can add empty item6 and item10 columns to data frame A and empty item1 item2 item3 columns to data frame B and then do rbind – MonahAbouAlezz Jan 08 '20 at 11:07
  • Hi Ronak, with a simple merge I get item1 twice in the dataset, once "item1" and one "item1.x". I need to merge those into 1 column to avoid duplicates. Not manually, but in a scalable manner. In that sence my question is a little different then the proposed duplicate question. – Jeroen Jan 08 '20 at 11:55
  • dplyr::bind_rows(A,B) – Jerb Jan 08 '20 at 12:16

0 Answers0