recode_na_if: Recode NA as another value with some conditions

Description Usage Arguments Examples

View source: R/recode_na_if.R

Description

Recode NA as another value with some conditions

Usage

1
recode_na_if(df, grouping_cols = NULL, target_groups = NULL, replacement = 0)

Arguments

df

A data.frame object with missing values

grouping_cols

Character columns to use for grouping the data

target_groups

Character Recode NA as if and only if the grouping column is in this vector of values

replacement

Values to use to replace NAs for IDs that meet the requirements. Defaults to 0.

Examples

1
2
3
4
some_data <- data.frame(ID=c("A1","A2","A3", "A4"),
A=c(5,NA,0,8), B=c(10,0,0,1),C=c(1,NA,NA,25))
# Replace NAs with 0s only for IDs in A2 and A3
recode_na_if(some_data,"ID",c("A2","A3"),replacement=0)

mde documentation built on Feb. 10, 2022, 5:08 p.m.

Related to recode_na_if in mde...