Open 1toMany left.csv:

Open 1toMany right.csv:

left <- read.csv('1toMany left.csv')

right <- read.csv('1toMany right.csv')

left

  key  Veggies

1 Mon Broccoli

2 Wed   Celery

3 Thu  Lettuce

4 Fri  Spinach

right

  key   Fruits

1 Mon   Apples

2 Mon  Bananas

3 Mon Cherries

4 Tue   Apples

5 Tue  Bananas

6 Wed   Apples

7 Wed Cherries

8 Fri   Apples

 

outer_full <- merge(x = left, y = right, by = 'key', all = TRUE)

outer_full

  key  Veggies   Fruits

1 Fri  Spinach   Apples

2 Mon Broccoli   Apples

3 Mon Broccoli  Bananas

4 Mon Broccoli Cherries

5 Thu  Lettuce     <NA>

6 Wed   Celery   Apples

7 Wed   Celery Cherries

8 Tue     <NA>   Apples

9 Tue     <NA>  Bananas

# Or with the dplyr package

library(dplyr)

f_join <- left %>% full_join(right, by = 'key')

# Or by default

f_join <- left %>% full_join(right)

outer_full

  key  Veggies   Fruits

1 Fri  Spinach   Apples

2 Mon Broccoli   Apples

3 Mon Broccoli  Bananas

4 Mon Broccoli Cherries

5 Thu  Lettuce     <NA>

6 Wed   Celery   Apples

7 Wed   Celery Cherries

8 Tue     <NA>   Apples

9 Tue     <NA>  Bananas

Functions referenced:

read.csv

merge

full_join (page 28)

More information:

RStudio Data Wrangling Cheatsheet

--- The End ---