recode_key: recode_key

Description Usage Arguments Value See Also Examples

View source: R/recode_key.R

Description

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.

Usage

1
recode_key(df, key)

Arguments

df

data frame

key

data frame with two columns, "Variable" and "Missing.Value"

Value

data frame with all missing values recoded to NA

See Also

Other functions for recoding missing values: recode_missing

Examples

 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)

HallLab/clarite documentation built on Oct. 27, 2020, 6:27 p.m.