[R] how to concatenate factor vectors?

Sam Steingold sds at gnu.org
Thu Oct 18 06:44:24 CEST 2012


How do I concatenate two vectors of factors?
--8<---------------cut here---------------start------------->8---
> a <- factor(5:1,levels=1:9)
> b <- factor(9:1,levels=1:9)
> str(c(a,b))
 int [1:14] 5 4 3 2 1 9 8 7 6 5 ...
> str(unlist(list(a,b),use.names=FALSE))
 Factor w/ 9 levels "1","2","3","4",..: 5 4 3 2 1 9 8 7 6 5 ...
--8<---------------cut here---------------end--------------->8---
so, unlist(list()) works.
is there a better way or is this how this is supposed to be done?
Thanks!
-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://honestreporting.com
http://think-israel.org http://thereligionofpeace.com http://mideasttruth.com
(lisp programmers do it better)



More information about the R-help mailing list