Doesn't: x <- sample(0:2,100,TRUE)
y <- structure(factor(x,labels=c("alive","dead","missed")), orig.labs=x) do what you want? -- Bert > The OP wanted to "associate" the label "alive" with the value 0, but didn't > want the underlying value in x to change. The construction > > y <- factor(x,labels=c("alive","dead","missed")) > > creates a factor, y, where the underlying factor value is 1 and the label is > "alive" where x had the value of 0. Without retaining the vector x, or > knowing how y was created, one can't get back to the original value of 0. I > am agnostic about whether that is good or bad, but it seems that your > approach does not meet the OP's original request. Am I missing someting? > > Dan > > Daniel Nordlund > Bothell, WA USA > > ______________________________________________ > 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. > -- "Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions." -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics ______________________________________________ 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.