Thank you very much to all of you for the responses! Phil, the following two examples worked well in re-categorizing. Is there any way I can retain my original data.frame format? Once I re-categorize the data, the format becomes numeric and the original column names are not retained. I probably should have mentioned this earlier - I plan on using the re-categorized data for coxph using the surv() function.
Here's how I am applying the re-categorization to my data: ***************************************************************************** library(survival) library(car) gg <- read.table("k.csv", header=TRUE, sep = ",") col = dim(genot)[2] for(i in 1:col) { aa<- recode(gg[,i], "c(1,2)='1'") } for(i in 1:col) { dd<-factor(gg[,i],levels=0:2,labels=c('0','1','1')) } Thanks, CC On Sat, Jul 17, 2010 at 2:15 PM, Phil Spector <spec...@stat.berkeley.edu>wrote: > Please look at Peter Dalgaard's response a little more > carefully. There's a big difference between the levels= > argument (which must be unique) and the labels= argument (which need not > be). Here are two ways > to do what you want: > > d = 0:2 >> factor(d,levels=0:2,labels=c('0','1','1')) >> > [1] 0 1 1 > >> library(car) >> recode(d,"c(1,2)='1'") >> > [1] 0 1 1 > > > - Phil Spector > Statistical Computing Facility > Department of Statistics > UC Berkeley > spec...@stat.berkeley.edu > > > > -- Thanks, CC [[alternative HTML version deleted]] ______________________________________________ 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.