Claus O'Rourke
2013-Aug-09 14:10 UTC
[R] Splitting a categorical variable into multiple variables
Hello R-Help, I have a variable with > 32 levels and I'd like to split this into two variables such that both new variables have >= 32 variables. This is to handle the limit of 32 level predictor variables in R's Random Forest implementation. Might someone be able to suggest an elegant way to do this? I've tried googling for this, but haven't hit the right search terms. Regards
Bert Gunter
2013-Aug-09 14:35 UTC
[R] Splitting a categorical variable into multiple variables
If I understand what you mean, just recode them. z <- factor(letters[1:3]) z zz <- factor(ifelse( z %in% c("a", "b"),"d" ,z)) zz Cheers, Bert On Fri, Aug 9, 2013 at 7:10 AM, Claus O'Rourke <claus.orourke at gmail.com> wrote:> Hello R-Help, > I have a variable with > 32 levels and I'd like to split this into two > variables such that both new variables have >= 32 variables. This is > to handle the limit of 32 level predictor variables in R's Random > Forest implementation. Might someone be able to suggest an elegant way > to do this? I've tried googling for this, but haven't hit the right > search terms. > > Regards > > ______________________________________________ > R-help at 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm