jrepl: Join and Replace Values.

View source: R/jrepl.R

jreplR Documentation

Join and Replace Values.

Description

Replace a columns values with matches in a different dataset. Author: Bryce Chamberlain.

Usage

jrepl(
  x,
  y,
  by,
  replace.cols,
  na.only = FALSE,
  only.rows = NULL,
  verbose = FALSE,
  viewalldups = FALSE,
  warn = FALSE
)

Arguments

x

Main dataset which will have new values. This data set will be returned with new values.

y

Supporting dataset which has the id and new values.

by

Vector of join column names. A character vector if the names match. A named character vector if they don't.

replace.cols

Vector of replacement column names, similar format as by.

na.only

Only replace values that are NA.

only.rows

Select rows to be affected. Default checks all rows.

verbose

Print via cat information about the replacement.

viewalldups

Set to TRUE to see all duplicates

warn

Set to TRUE to see warnings.

Value

x with new values.

Examples


df1 = utils::head( sleep )
group.reassign = data.frame( 
  id.num = factor( c( 1, 3, 4 ) ), 
group.replace = factor( c( 99, 99, 99 ) ) 
)

jrepl( 
  x = df1, 
  y = group.reassign, 
  by = c( 'ID' = 'id.num' ), 
  replace.cols = c( 'group' = 'group.replace' ) 
)

# doesn't affect since there are no NAs in group.
jrepl( 
  x = df1,
  y = group.reassign, 
  by = c( 'ID' = 'id.num' ), 
  replace.cols = c( 'group' = 'group.replace' ), 
  na.only = TRUE  
) 

oliver-wyman-actuarial/easyr documentation built on Jan. 27, 2024, 4:37 a.m.