Does anyone know if tidyr::complete()
supports grouping via group_by()
?
To be precise: I have some data frame that looks like this
df <- data.frame(
"ID" = rep(1:2, each = 2),
"Col1" = c("A", NA, "AA", NA),
"Col2" = c("B", "C", "BB", "CC"))
Now i'd like to use complete()
and group_by()
to compute all possible combinations per group!
df %>%
group_by(ID) %>%
complete(Col1, Col2)
Error in .Call("dplyr_left_join_impl", PACKAGE = "dplyr", x, y, by_x, :
negative length vectors are not allowed
This causes an error. However, using complete()
without grouping works but thats not what i want.
df %>%
complete(Col1, Col2)
Questions:
- Have I done anything wrong, or does
complete()
simply not work with group_by
?
- If so, how could I do this instead (preferably without using a loop)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…