Skip to content
Prev 43767 / 398513 Next

correction to the previously asked question (about merging factors)

What about the following: 

 > F1 <- factor(c("b", "a"))
 > F2 <- factor(c("c", "b"))
 > k1 <- length(F1)
 > k2 <- length(F2)
 > F12.lvls <- unique(c(levels(F1), levels(F2)))
 > F. <- factor(rep(F12.lvls[1], k1+k1), levels=F12.lvls)
 > F.[1:k1] <- F1
 > F.[-(1:k1)] <- F2
 > F.
[1] b a c b
Levels: a b c

      This saves converting the factors to characters, which might save 
computer time at the expense of your time. 
      hope this helps. 
      spencer graves
Svetlana Eden wrote: