在清洗收据时遇到了报错,代码是这样
FamilyPovertyIncomeRatio=ifelse(demo$indfmpir<=1.3,"low_income",
ifelse(demo$indfmpir>1.3&demo$indfmpir<=3.5,"medium_income",
ifelse(demo$indfmpir>3.5,"high_income", )))
Error in `mutate()`:
! Problem while computing `FamilyPovertyIncomeRatio = ifelse(...)`.
Caused by error in `ifelse()`:
! argument "no" is missing, with no default
Run `r
原因:ifelse函数,加少了一个参数。在判断为no时R不知返回什么。
有一种情况,在缺乏该参数时不会报错,即在判断为no时R没有指可以返回,即全部指都是yes。
FamilyPovertyIncomeRatio=ifelse(demo$indfmpir<=1.3,"low_income",
ifelse(demo$indfmpir>1.3&demo$indfmpir<=3.5,"medium_income",
ifelse(demo$indfmpir>3.5,"high_income","others")))
这样就正常了。