na_if
Requires dplyr package.
Usage
Used to assign NA to invalid values of a variable. This is required in order to compute accurate summary statistics.
Usage:
dataframe$variable <- na_if(dataframe$variable, invalid_value)
- Replaces all instances of
invalid_valueindataframe$variablewithNA.
Example
rm(list=ls())
library(dplyr)
df <- read.csv("IPUMS_ACS2019_CA_1.csv")
df$INCWAGE <- na_if(df$INCWAGE, 999999)
df$INCWAGE <- na_if(df$INCWAGE, 999998)
This code replaces all instances of 999999 and 999998 in df$INCWAGE with NA.