Rolf Turner wrote: >> Does it even work? (What if it is the first or the 2nd level that is >> absent? > > Yes it works. What's the problem? > > To beat it to death: if the second level of fff is absent then > fff will consist entirely of 1's and 3's, > and so c("U","A","S")[fff] will consist entirely of U's and S's. > I can then set the levels to be > c("U","A","S") and get what I want. You didn't say that fff was numeric.
If fff is a factor, then we have the problem: > attach(read.table(stdin(),header=T)) 0: fff 1: Unit 2: Scholarship 3: Scholarship 4: Unit 5: > c("U","A","S")[fff] [1] "A" "U" "U" "A" Actually we have another problem too, namely sort order.... Anyway, sort the labels, and > c("A","S", "U")[fff] [1] "S" "A" "A" "S" If you have the data as numeric codes, then of course factor(fff, levels=1:3, labels=c("U","A","S")) does the trick too. -- O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ 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.