我尝试使用以下代码使用 ifelse 语句对数据帧 df 中的列进行离散化。aar 列包含从 0 到 12 的十进制值和 NA。我检查数值是否并将其分配给如下类别。
> df= df%>% mutate(arr2= ifelse( grepl("NA", aar)==T, "NA",
> ifelse(as.numeric(aar)==0, "0-0.99", ifelse(as.numeric(aar))==1,
> "1-1.99", ifelse(as.numeric(aar)==2, "2-2.99",
> ifelse(as.numeric(aar)==3, "3-3.99", ifelse(as.numeric(aar)==4,
> "4-4.99", ifelse(as.numeric(aar)==5, "5-5.99",
> ifelse(as.numeric(aar)==6, "6-6.99", ifelse(as.numeric(aar)==7,
> "7-7.99", ifelse(as.numeric(aar)==8,
> "8-8.99",ifelse(as.numeric(aar)==9, "9-9.99",
> ifelse(as.numeric(aar)==10, "10-10.99", ifelse(as.numeric(aar)==11,
> "11-11.99", "12" )))))))))))))
但我收到以下错误,
Error: unused arguments ("1-1.99", ifelse(as.numeric(c("0", "NA", "0",......
我究竟做错了什么?任何人都可以帮我解决这个问题吗?