I would like to fill up missing cases in the problem
dataframe in a way that for each missing id (3 in group 1 and 2 in group 2) I get a new line with the group # and and the id and NA for the target.
problem <-
data.frame(id = c(c(1,2,4,5),c(1,3,4,5)), group = c(rep(1,4), rep(2,4)), target = c(rep(c('A','B'),4)))
#id group target
# 1 1 A
# 2 1 B
# 4 1 A
# 5 1 B
# 1 2 A
# 3 2 B
# 4 2 A
# 5 2 B
with the id list from the full
dataframe.
full <- data.frame(id = seq(1,5))
#id
# 1
# 2
# 3
# 4
# 5
desired result should be:
#id group target
# 1 1 A
# 2 1 B
# 3 1 NA
# 4 1 A
# 5 1 B
# 1 2 A
# 2 2 NA
# 3 2 B
# 4 2 A
# 5 2 B
I went through all the joins I can think of but got stuck with dplyr
and tidyr
not really doing what I need.