I'm having difficulty creating a new factor variable from a preexisting numerical variable. I have a numerical variable Age with the age of my participants but want to create a factor variable that categorizes participants' age into different categories. Whenever I run my code I get an error:
"Error: argument "no" is missing, with no default."
I have tried different variations of the below code such as the new factor level without quotes, using : for ranges, etc. My code is below.
data.frame%>%
mutate(Age = ifelse(Age < 20, "0"),
ifelse(Age >= 20 & Age <= 29, "1"),
ifelse(Age >=30 & Age <= 39, "2"),
ifelse(Age >= 40 & Age <=49, "3"),
ifelse(Age >= 50 & Age <= 59, "4"),
ifelse(Age >= 60 & Age <= 69, "5"),
ifelse(Age >= 70, "6", NA))