Error: Problem with `mutate()` input `chldwork`.
x Input must be a vector, not a `formula` object.
ℹ Input `chldwork` is `case_when(...)`.
Run `rlang::last_error()` to see where the error occur
I keep getting this error when I try running this code:
d5clean <- d5clean %>%
mutate(chldwork = case_when(is.na(curjobr5) & wrmm12r5 == 0 & wrno12r5 == 0 & wrow12r5 == 0 ~ 0,
is.na(curjobr5) & wrmm12r5 == 1 & wrno12r5 == 0 & wrow12r5 == 0 ~ 1,
is.na(curjobr5) & wrmm12r5 == 1 & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
is.na(curjobr5) & wrmm12r5 == 1 & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
is.na(curjobr5) & wrmm12r5 == 0 & wrno12r5 == 0 & wrow12r5 == 1 ~ 1,
is.na(curjobr5) & wrmm12r5 == 0 & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
is.na(curjobr5) & wrmm12r5 == 0 & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
is.na(curjobr5) & wrmm12r5 == 1 & wrno12r5 == 0 & wrow12r5 == 0 ~ 1,
curjobr5 == 0 & is.na(wrmm12r5) & wrno12r5 == 0 & wrow12r5 == 0 ~ 0,
curjobr5 == 0 & is.na(wrmm12r5) & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
curjobr5 == 0 & is.na(wrmm12r5) & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
curjobr5 == 1 & is.na(wrmm12r5) & wrno12r5 == 0 & wrow12r5 == 0 ~ 1,
curjobr5 == 1 & is.na(wrmm12r5) & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
curjobr5 == 1 & is.na(wrmm12r5) & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
curjobr5 == 0 & wrmm12r5== 0 & is.na(wrno12r5) & wrow12r5 == 0 ~ 0,
curjobr5 == 0 & wrmm12r5== 0 & is.na(wrno12r5) & wrow12r5 == 1 ~ 1,
curjobr5 == 0 & wrmm12r5== 1 & is.na(wrno12r5) & wrow12r5 == 1 ~ 1,
curjobr5 == 1 & wrmm12r5== 1 & is.na(wrno12r5) & wrow12r5 == 1 ~ 1,
curjobr5 == 1 & wrmm12r5== 0 & is.na(wrno12r5) & wrow12r5 == 0 ~ 1,
curjobr5 == 1 & wrmm12r5== 0 & is.na(wrno12r5) & wrow12r5 == 0 ~ 1,
curjobr5 == 0 & wrmm12r5==0 & wrno12r5 == 0 & is.na(wrow12r5) ~ 0,
curjobr5 == 0 & wrmm12r5==0 & wrno12r5 == 1 & is.na(wrow12r5) ~ 1,
curjobr5 == 0 & wrmm12r5==1 & wrno12r5 == 1 & is.na(wrow12r5) ~ 1,
curjobr5 == 1 & wrmm12r5==1 & wrno12r5 == 1 & is.na(wrow12r5) ~ 0,
curjobr5 == 1 & wrmm12r5==0 & wrno12r5 == 0 & is.na(wrow12r5) ~ 1,
curjobr5 == 1 & wrmm12r5==1 & wrno12r5 == 0 & is.na(wrow12r5) ~ 1,
curjobr5 == 1 & wrmm12r5==1 & wrno12r5 == 1 & is.na(wrow12r5) ~ 1,
curjobr5 == 0 & wrmm12r5 == 0 & wrno12r5 == 0 & wrow12r5 == 0 ~ 0,
curjobr5 == 1 & wrmm12r5 == 0 & wrno12r5 == 0 & wrow12r5 == 0 ~ 1,
curjobr5 == 1 & wrmm12r5 == 1 & wrno12r5 == 0 & wrow12r5 == ~ 1,
curjobr5 == 1 & wrmm12r5 == 1 & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
curjobr5 == 1 & wrmm12r5 == 1 & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
curjobr5 == 0 & wrmm12r5 == 1 & wrno12r5 == 0 & wrow12r5 == 0 ~ 1,
curjobr5 == 0 & wrmm12r5 == 1 & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
curjobr5 == 0 & wrmm12r5 == 1 & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
curjobr5 == 0 & wrmm12r5 == 0 & wrno12r5 == 1 & wrow12r5 == 0 ~ 1,
curjobr5 == 0 & wrmm12r5 == 0 & wrno12r5 == 1 & wrow12r5 == 1 ~ 1,
curjobr5 == 0 & wrmm12r5 == 0 & wrno12r5 == 0 & wrow12r5 == 1 ~ 1,
TRUE ~ as.numeric(88)))
I'm trying to combine multiple work variables into one work variables with several non-random missing values. Any ideas on how to make it work?
I was able to run this code fine:
d4clean <- d4clean %>%
mutate(chldwork = case_when(curjobr4 == 0 & wrbf12r4 == 0 ~ 0, #condition 1
curjobr4 == 1 & wrbf12r4 == 1 ~ 1, #condition 2
curjobr4 == 1 & wrbf12r4 == 0 ~ 1, #condition 3
curjobr4 == 0 & wrbf12r4 == 1 ~ 1, #condition 4
is.na(curjobr4) & wrbf12r4 == 1 ~ 1, #condition 5
is.na(curjobr4) & wrbf12r4 == 0 ~ 0, #condition 6
TRUE ~ 99)) #all other cases
Also, I'm not sure if this includes all of the correct cases I'd need to merge. I'm going a little cross-eyed at this point.
In one of the lines, the value to be compared is missing
...
curjobr5 == 1 & wrmm12r5 == 1 & wrno12r5 == 0 & wrow12r5 == ~ 1,
^
...
which caused the error