df1 = data.frame(Id = c(1:16), Product = c(rep("Fishcake", 12), rep("Twit", 4)))
df2 = data.frame(Id = c(2, 4, 6, 8, 13), Word = c(rep("Sausage", 3), rep("Crumpo", 2)))
# Outer join:
merge(x = df1, y = df2, by = "Id", all = TRUE)
## Id Product Word
## 1 1 Fishcake <NA>
## 2 2 Fishcake Sausage
## 3 3 Fishcake <NA>
## 4 4 Fishcake Sausage
## 5 5 Fishcake <NA>
## 6 6 Fishcake Sausage
## 7 7 Fishcake <NA>
## 8 8 Fishcake Crumpo
## 9 9 Fishcake <NA>
## 10 10 Fishcake <NA>
## 11 11 Fishcake <NA>
## 12 12 Fishcake <NA>
## 13 13 Twit Crumpo
## 14 14 Twit <NA>
## 15 15 Twit <NA>
## 16 16 Twit <NA>
# Left outer:
merge(x = df1, y = df2, by = "Id", all.x = TRUE)
## Id Product Word
## 1 1 Fishcake <NA>
## 2 2 Fishcake Sausage
## 3 3 Fishcake <NA>
## 4 4 Fishcake Sausage
## 5 5 Fishcake <NA>
## 6 6 Fishcake Sausage
## 7 7 Fishcake <NA>
## 8 8 Fishcake Crumpo
## 9 9 Fishcake <NA>
## 10 10 Fishcake <NA>
## 11 11 Fishcake <NA>
## 12 12 Fishcake <NA>
## 13 13 Twit Crumpo
## 14 14 Twit <NA>
## 15 15 Twit <NA>
## 16 16 Twit <NA>
# Right outer:
merge(x = df1, y = df2, by = "Id", all.y = TRUE)
## Id Product Word
## 1 2 Fishcake Sausage
## 2 4 Fishcake Sausage
## 3 6 Fishcake Sausage
## 4 8 Fishcake Crumpo
## 5 13 Twit Crumpo
# Cross join:
merge(x = df1, y = df2, by = NULL)
## Id.x Product Id.y Word
## 1 1 Fishcake 2 Sausage
## 2 2 Fishcake 2 Sausage
## 3 3 Fishcake 2 Sausage
## 4 4 Fishcake 2 Sausage
## 5 5 Fishcake 2 Sausage
## 6 6 Fishcake 2 Sausage
## 7 7 Fishcake 2 Sausage
## 8 8 Fishcake 2 Sausage
## 9 9 Fishcake 2 Sausage
## 10 10 Fishcake 2 Sausage
## 11 11 Fishcake 2 Sausage
## 12 12 Fishcake 2 Sausage
## 13 13 Twit 2 Sausage
## 14 14 Twit 2 Sausage
## 15 15 Twit 2 Sausage
## 16 16 Twit 2 Sausage
## 17 1 Fishcake 4 Sausage
## 18 2 Fishcake 4 Sausage
## 19 3 Fishcake 4 Sausage
## 20 4 Fishcake 4 Sausage
## 21 5 Fishcake 4 Sausage
## 22 6 Fishcake 4 Sausage
## 23 7 Fishcake 4 Sausage
## 24 8 Fishcake 4 Sausage
## 25 9 Fishcake 4 Sausage
## 26 10 Fishcake 4 Sausage
## 27 11 Fishcake 4 Sausage
## 28 12 Fishcake 4 Sausage
## 29 13 Twit 4 Sausage
## 30 14 Twit 4 Sausage
## 31 15 Twit 4 Sausage
## 32 16 Twit 4 Sausage
## 33 1 Fishcake 6 Sausage
## 34 2 Fishcake 6 Sausage
## 35 3 Fishcake 6 Sausage
## 36 4 Fishcake 6 Sausage
## 37 5 Fishcake 6 Sausage
## 38 6 Fishcake 6 Sausage
## 39 7 Fishcake 6 Sausage
## 40 8 Fishcake 6 Sausage
## 41 9 Fishcake 6 Sausage
## 42 10 Fishcake 6 Sausage
## 43 11 Fishcake 6 Sausage
## 44 12 Fishcake 6 Sausage
## 45 13 Twit 6 Sausage
## 46 14 Twit 6 Sausage
## 47 15 Twit 6 Sausage
## 48 16 Twit 6 Sausage
## 49 1 Fishcake 8 Crumpo
## 50 2 Fishcake 8 Crumpo
## 51 3 Fishcake 8 Crumpo
## 52 4 Fishcake 8 Crumpo
## 53 5 Fishcake 8 Crumpo
## 54 6 Fishcake 8 Crumpo
## 55 7 Fishcake 8 Crumpo
## 56 8 Fishcake 8 Crumpo
## 57 9 Fishcake 8 Crumpo
## 58 10 Fishcake 8 Crumpo
## 59 11 Fishcake 8 Crumpo
## 60 12 Fishcake 8 Crumpo
## 61 13 Twit 8 Crumpo
## 62 14 Twit 8 Crumpo
## 63 15 Twit 8 Crumpo
## 64 16 Twit 8 Crumpo
## 65 1 Fishcake 13 Crumpo
## 66 2 Fishcake 13 Crumpo
## 67 3 Fishcake 13 Crumpo
## 68 4 Fishcake 13 Crumpo
## 69 5 Fishcake 13 Crumpo
## 70 6 Fishcake 13 Crumpo
## 71 7 Fishcake 13 Crumpo
## 72 8 Fishcake 13 Crumpo
## 73 9 Fishcake 13 Crumpo
## 74 10 Fishcake 13 Crumpo
## 75 11 Fishcake 13 Crumpo
## 76 12 Fishcake 13 Crumpo
## 77 13 Twit 13 Crumpo
## 78 14 Twit 13 Crumpo
## 79 15 Twit 13 Crumpo
## 80 16 Twit 13 Crumpo
Date sequence
seq(as.Date("2015/1/1"), by = "month", length.out = 12)
## [1] "2015-01-01" "2015-02-01" "2015-03-01" "2015-04-01" "2015-05-01"
## [6] "2015-06-01" "2015-07-01" "2015-08-01" "2015-09-01" "2015-10-01"
## [11] "2015-11-01" "2015-12-01"