jeudi 23 juin 2016

Error: unused arguments in ifelse in R

I tried to discretise a column in dataframe df using ifelse statements using the following code. The column aar contains decimal values from 0 to 12 and NAs. I check if the numeric value and assign it to the categories as below.

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

But I get the following error,

Error: unused arguments ("1-1.99", ifelse(as.numeric(c("0", "NA", "0",...... 

What am I doing wrong? Can anyone kindly help me to fix this please?

Aucun commentaire:

Enregistrer un commentaire