Skip to content

New factor from two olds factors

2 messages · Jorge Magalhães, Uwe Ligges

#
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")))
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=(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.
#
Jorge Magalh?es wrote:
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"))
But using as.numeric(), I guess.
For example: 
 factor(ifelse(array3 < 5, 1, 2))

Uwe Ligges