replyr_coalesce: Augment a data frame by adding additional rows.

Description Usage Arguments Value Examples

View source: R/coalesce.R

Description

Note: do not count on order of resulting data. Also only added rows are altered by the fill instructions.

Usage

1
2
3
4
5
6
7
8
9
replyr_coalesce(
  data,
  support,
  ...,
  fills = NULL,
  newRowColumn = NULL,
  copy = TRUE,
  tempNameGenerator = mk_tmp_name_source("replyr_coalesce")
)

Arguments

data

data.frame data to augment

support

data.frame rows of unique key-values into data

...

not used, force later arguments to bind by name

fills

list default values to fill in columns

newRowColumn

character if not null name to use for new row indicator

copy

logical if TRUE copy support to data's source

tempNameGenerator

temp name generator produced by wrapr::mk_tmp_name_source, used to record dplyr::compute() effects.

Value

augmented data

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# single column key example
data <- data.frame(year = c(2005,2007,2010),
                   count = c(6,1,NA),
                   name = c('a','b','c'),
                   stringsAsFactors = FALSE)
support <- data.frame(year=2005:2010)
filled <- replyr_coalesce(data, support,
                          fills=list(count=0))
filled <- filled[order(filled$year), ]
filled

# complex key example
data <- data.frame(year = c(2005,2007,2010),
                   count = c(6,1,NA),
                   name = c('a','b','c'),
                   stringsAsFactors = FALSE)
support <- expand.grid(year=2005:2010,
                   name= c('a','b','c','d'),
                   stringsAsFactors = FALSE)
filled <- replyr_coalesce(data, support,
                          fills=list(count=0))
filled <- filled[order(filled$year, filled$name), ]
filled

WinVector/replyr documentation built on Oct. 22, 2020, 8:07 p.m.