there's a recode function in the Hmisc package, but it's difficult (at least for me) to find documentation for it
library(Hmisc) week <- c('SAT', 'SUN', 'MON', 'FRI'); recode(week,c('SAT', 'SUN', 'MON', 'FRI'),1:4) HTH -- View this message in context: http://n4.nabble.com/How-to-add-a-variable-to-a-dataframe-whose-values-are-conditional-upon-the-values-of-an-existing-vare-tp1571214p1572261.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.