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))
使用tidyr::complete
,只需要指定季节和组的每个组合即可:
tidyr::complete(data, season, group)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.