Reputation: 2527
Stata's fillin
command makes a dataset rectangular.
How can I do the same in R?
As a reproducible example, say that I have the data below:
data <- data.frame(season = c("2016-17","2017-18","2018-19", "2018-19"), group=c("A","A","A","B"), value=c(1,2,3,6))
I would like to get the following:
data_wanted <- data.frame(season = c("2016-17","2017-18","2018-19", "2018-19", "2016-17", "2017-18"), group=c("A","A","A","B","B","B"),value=c(1,2,3,6,NA,NA))
Upvotes: 0
Views: 640
Reputation: 60060
Using tidyr::complete
, just specify that you want every combination of season and group:
tidyr::complete(data, season, group)
Upvotes: 3