> Well, I think that's kind of overkill. Depends whether you want to recode all or some, and how robust you want the answer to be. recode() allows you to recode a few levels of many, without dependence on level ordering; that's kind of neat.
tbh, though, I don't use recode() a lot; I generally find myself need to change a fair proportion of level labels. But I do get nervous about relying on specific ordering; it can break without visible warning if the data change (eg if you lose a factor level with a slightly different data set, integer indexing will give you apparently valid reassignment to the wrong new codes). So I tend to go via named vectors even if it costs me a lot of typing. For example to change lcase<-c('a', 'b', 'c') to c('B', 'A', 'C') I'll use something like c(a='B', b='A', c='C')[lcase] or, if lcase were a factor, c(a='B', b='A', c='C')[as.character(lcase)] Unlike using the numeric levels, that doesn't fail if some of the levels I expect are absent; it only fails (and does so visibly) when there's a value in there that I haven't assigned a coding to. So it's a tad more robust. Steve E ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.