I have this data with two NA values in the Occupation
column and I am trying to use dplyr
to replace the values with the word Pensioner
.
This is what I have.
data <- data %>%
filter(is.na(Occupation) & Yrs_Empleo <= -999 & Organisation == "XNA" & Income_type == "Pensioner")
I have tried mutate_at
and replace_na
and some ifelse
statements but I just cannot seem to figure out how to correctly do it.
So basically I am trying to replace all NA
values in column Occupation
based on three conditions and then once those three conditions have been met, replace with the work retired
.
structure(list(Yrs_Empleo = c(1.74520547945205, 3.25479452054795,
0.616438356164384, 8.32602739726027, 8.32328767123288, 4.35068493150685,
8.57534246575342, 1.23013698630137, -1000.66575342466, 5.53150684931507,
1.86027397260274, -1000.66575342466, 7.44383561643836), Occupation = c("Laborers",
"Core staff", "Laborers", "Laborers", "Core staff", "Laborers",
"Accountants", "Managers", NA, "Laborers", "Core staff", NA,
"Laborers"), Organisation = c("Business Entity Type 3", "School",
"Government", "Business Entity Type 3", "Religion", "Other",
"Business Entity Type 3", "Other", "XNA", "Electricity", "Medicine",
"XNA", "Business Entity Type 2"), Income_type = c("Working",
"State servant", "Working", "Working", "Working", "State servant",
"Commercial associate", "State servant", "Pensioner", "Working",
"Working", "Pensioner", "Working")), .Names = c("Yrs_Empleo",
"Occupation", "Organisation", "Income_type"), row.names = c(NA,
13L), class = "data.frame")
See Question&Answers more detail:
os