Similar idea to
pandas.replace
method using a dictionary for the value
argument. Note: only
works with columns that are of type numeric (including integer) or character.
revalue_col(df, colname, dict, default_value = NULL, suppress_warnings = FALSE)
dataframe.
character. Name of column to be relabelled
a named vector. names(dict)
are the 'keys' i.e. the
existing values in df[[colname]]
to be replaced. These should be
unique. An error is raised if non-unique values are found in
names(dict)
default value to use for values in df[[colname]]
that are not present in names(dict)
. By default this is NULL
,
meaning that values not present in names(dict)
will remain
unchanged.
bool. A warning is raised if the column to be
relabelled contains values not present in dict
. This message is
silenced if suppress_warnings
is TRUE
. Default value is
FALSE
.
dataframe