>source

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

이 코드를 실행하려고하면이 오류가 계속 발생합니다.

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)))

여러 작업 변수를 여러 비 무작위 결 측값이있는 하나의 작업 변수로 결합하려고합니다. 작동하는 방법에 대한 아이디어가 있습니까?

이 코드를 잘 실행할 수있었습니다.

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

또한 여기에 병합해야 할 모든 올바른 사례가 포함되어 있는지 확실하지 않습니다. 나는이 시점에서 약간의 눈을 가릴 것입니다.

  • 답변 # 1

    행 중 하나에서 비교할 값이 누락되었습니다.

    ...
    curjobr5 == 1 & wrmm12r5 == 1 & wrno12r5 == 0 & wrow12r5 ==  ~ 1,
                                                                ^
    ...
    
    

    오류를 일으킨

관련 자료

  • 이전 modulenotfounderror - 'python'이라는 모듈이 없습니다
  • 다음 javascript - 하나의 함수에서 두 개의 jquery 문 호출