[R] New factor from two olds factors
Uwe Ligges
ligges at statistik.uni-dortmund.de
Thu May 1 15:46:50 CEST 2003
Jorge Magalhães wrote:
>
> Hi,
>
> Suppose i have two factors:
>
> factor1<-Structure(factor(c(1,3,2,1,2,1,2,1,3),levels=1:3),
> .Label=c("Yes","No","NY")))
For sure you mean
factor1 <- structure(factor(c(1,3,2,1,2,1,2,1,3), levels=1:3),
Label=c("Yes","No","NY"))
> factor2<-Structure(factor(c(2,1,2,1,3,2,2,1,3),levels=1:3),
> .Label=c("Yes","No", "NY")))
>
> i want define a new factor from the factors 1 and 2. For that i tried:
>
> >array3<- is.numeric(factor1)+is.numeric(factor2)
But using as.numeric(), I guess.
> array3=(3,4,4,2,5,3,4,2,6)
>
> Now i need to define two new classes: if 2,3 and 4 ----->> class1 else class2
>
> What is the best way for making that?
>
> Thanks in the advance.
>
> Jorge M.
For example:
factor(ifelse(array3 < 5, 1, 2))
Uwe Ligges
More information about the R-help
mailing list