complete_se: complete by standard interface

Description Usage Arguments Details Value Examples

View source: R/complete_se.R

Description

Complete a data frame with missing combinations of data. Turns implicit missing values into explicit missing values.

Usage

1
complete_se(data, col_terms, fill = list(), env = parent.frame())

Arguments

data

A data frame or tbl.

col_terms

A character vector of column names or expressions to complete by.

fill

A list that for each variable supplies a single value to use instead of NA for missing combinations.

env

The environment as an argument (in case the function is called from another function).

Details

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.

Value

The data frame with implicit missing values identified.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 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))

seplyr documentation built on Sept. 5, 2021, 5:12 p.m.