I'm translating Stata code to R code, but now I'm having some n00b troubles like this one.
This is my Stata code:
gen aposentadofam=1 if proprendaposent > 0 & proprendaposent ~=.;
replace aposentadofam=0 if proprendaposent == 0 | proprendaposent ==.;
And this is what I tried to do in R:
# pemg <- mutate(pemg, aposentadofam = NA_real_)
# pemg <- mutate(pemg, aposentadofam = case_when(proprendaposent >0 & !is.na(proprendaposent) ~ 1, TRUE ~ aposentadofam))
# pemg <- mutate(pemg, aposentadofam = case_when(proprendaposent==0 | is.na(proprendaposent) ~ 0, TRUE ~ aposentadofam))
The line with is.na()
seems to be running correctly, but the one with !is.na()
does not. It gives me this error message:
LHS of case 1 (`proprendaposent > 0 & !is.na(proprendaposent) ~ 1`) must be a logical vector, not a `formula` object.
What should I do?