Description Usage Arguments Value See Also Examples
Recode multiple values to NA based on a data key listing values specific to each column.
Empty strings ("") and "NA" will be replaced by NA regardless of keys
Note: Replaced values must be a factor, integer, or numeric (other values are ignored). Float values may fail to convert due to rounding.
1 | recode_key(df, key)
|
df |
data frame |
key |
data frame with two columns, "Variable" and "Missing.Value" |
data frame with all missing values recoded to NA
Other functions for recoding missing values: recode_missing
1 2 3 4 5 6 7 8 9 10 11 | # Create an example dataset
df <- data.frame("ID" = 1:3,
"Age" = c(21,15, 34),
"Name" = c("John","Jane", "Jill"),
"Value1" = c("a", "b", "NA"),
"Value2" = c(1, 98, 99))
# Recode 'Value1' ("NA" is NA) and 'Value2' (98 and 99 are both NA)
key <- data.frame("Variable" = c("Value2", "Value2"),
"Missing Value" = c(98, 99))
# Run the function
recoded <- recode_key(df, key)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.