I am trying to create a new factor variable that is conditional based on a numeric variable within my dataframe. my ifelse argument works perfectly when I supply it a single inequality, but for the two categories that require a compound inequality, it doesn't work. I'm familiar with logic and conditions in other languages, and I'm thinking just my syntax is off?
Also, there seems to be times when you can use '&' and times to use '&&'. I'm used to always using '&&', so what is the difference here?
data$bin<-as.factor(ifelse(data$internet<=2.3225,"one",
ifelse(data$internet>2.3225 && data$internet<=4.425,"two",
ifelse(data$internet>4.425 && data$internet<=6.5275,"three",
ifelse(data$internet>6.5275,"four",NA)))))