Complete a data frame with missing combinations of data. Turns implicit missing values into explicit missing values.
complete_se(data, col_terms, fill = list(), env = parent.frame())
A data frame or tbl.
A character vector of column names or expressions to complete by.
A list that for each variable supplies a single value to use instead of NA for missing combinations.
The environment as an argument (in case the function is called from another function).
The data frame with implicit missing values identified.
This is a standard evaluation interface for tidyr::complete()
. The purpose of the function is to be able to use a vector of characters (column names) as the argument for expanding the data frame.
# NOT RUN {
# data frame used to illustrate tidyr::complete()
df <- wrapr::build_frame(
"group" , "item_id", "item_name", "value1", "value2" |
1 , 1 , "a" , 1L , 4L |
2 , 2 , "b" , 2L , 5L |
1 , 2 , "b" , 3L , 6L )
# columns to complete by
col_terms <- qc(group, item_id, item_name)
df %.>% complete_se(., col_terms)
df %.>% complete_se(., col_terms, fill = list(value1 = 0))
# with nesting
col_terms <- c("group", "tidyr::nesting(item_id, item_name)")
df %.>% complete_se(., col_terms)
df %.>% complete_se(., col_terms, fill = list(value1 = 0))
df %.>% complete_se(., col_terms, fill = list(value1 = 0, value2 = 0))
# }
Run the code above in your browser using DataLab