Just be careful about your final category - it assigns the last value to whatever values are left over that didn't meet any condition (including if a value is NA!) so make sure you want that to happen.Other examples of ways to use the ifelse() function:If you want to add a column with the mean of Weight by sex for each individual, you can do this with ifelse() like this:mydata$meanweight.bysex<-if