mardi 6 octobre 2020

Create new variable where all values that are not between the 1st and the 99th percentile are substituted with missing values (NA)

I want to copy the india04 dataframe and add a new variable called "incwage_adj" using mutate(), where all the income values between the 1st and the 99th percentile are substituted with missing values (NA). Packages:

library(tidyverse)
require(nycflights13)
data(diamonds)
load("india04.Rdata")

Code:

india04_new <- india04 %>%
mutate(incwage_adj = ifelse(incwage != quantile(india04_new2$incwage, 0.99), NA, incwage))

Aucun commentaire:

Enregistrer un commentaire