Re: [R] Splitting a categorical variable into multiple variables

2013-08-09 Thread Bert Gunter
Actually, I think it's pretty trivial if you do it in a smarter way than I previously suggested. I found this by reading ?levels (RTFM, Bert!) > z <- factor(letters[1:3]) > levels(z)[1:2]<- "d" ## no hardcoding names; just use indices > z [1] d d c Levels: d c Cheers, Bert On Fri, Aug 9, 2013 at

Re: [R] Splitting a categorical variable into multiple variables

2013-08-09 Thread Claus O'Rourke
Thanks Bert. I guess I was just wondering if there was a way to create the new factors automatically without me having to hard code the level names manually in my R code. Rgds Claus On Fri, Aug 9, 2013 at 3:42 PM, Bert Gunter wrote: > ... or if you want to keep the unchanged levels the same: >

Re: [R] Splitting a categorical variable into multiple variables

2013-08-09 Thread Bert Gunter
... or if you want to keep the unchanged levels the same: zz <- factor(ifelse( z %in% c("a", "b"),"d" ,levels(z)[z])) -- Bert On Fri, Aug 9, 2013 at 7:35 AM, Bert Gunter wrote: > If I understand what you mean, just recode them. > > z <- factor(letters[1:3]) > z > zz <- factor(ifelse( z %in% c("

Re: [R] Splitting a categorical variable into multiple variables

2013-08-09 Thread Bert Gunter
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 wrote: > Hello R-Help, > I have a variable with > 32 levels and I'd like to split this into two > variable

[R] Splitting a categorical variable into multiple variables

2013-08-09 Thread Claus O'Rourke
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 th