replaceDF: Replace multiple values in a data frame

Description Usage Arguments Details Value See Also Examples

View source: R/coin_assemble.R

Description

Given a data frame (or vector), this function replaces values according to a look up table or dictionary. In COINr this may be useful for exchanging categorical data with numeric scores, prior to assembly. Or for changing codes.

Usage

1
replaceDF(df, lookup)

Arguments

df

A data frame or a vector

lookup

A data frame with columns old (the values to be replaced) and new the values to replace with. See details.

Details

The lookup data frame must not have any duplicated values in the old column. This function looks for exact matches of elements of the old column and replaces them with the corresponding value in the new column. For each row of lookup, the class of the old value must match the class of the new value. This is to keep classes of data frames columns consistent. If you wish to replace with a different class, you should convert classes in your data frame before using this function.

Value

A data frame with replaced values

See Also

Examples

1
2
3
4
5
# replace sub-pillar codes in ASEM indicator metadata
codeswap <- data.frame(old = c("Conn", "Sust"), new = c("SI1", "SI2"))
# swap codes in both indmeta and aggmeta
replaceDF(ASEMIndMeta, codeswap)
replaceDF(ASEMAggMeta, codeswap)

COINr documentation built on Nov. 30, 2021, 9:06 a.m.