replace_df {COINr}R Documentation

Replace multiple values in a data frame


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.


replace_df(df, lookup)



A data frame or a vector


A data frame with columns old (the values to be replaced) and new the values to replace with. See 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.

This function replaces the now-defunct replaceDF() from COINr < v1.0.


A data frame with replaced values


# replace sub-pillar codes in ASEM indicator metadata
codeswap <- data.frame(old = c("Conn", "Sust"), new = c("SI1", "SI2"))
# swap codes in both iMeta
replace_df(ASEM_iMeta, codeswap)

[Package COINr version 1.1.7 Index]