[R] how to concatenate factor vectors?

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu Oct 18 16:53:24 CEST 2012

mood <- factor(c("blue", "sunny"))
skycolor <- factor(c("azure","blue","teal")

If factors are not defined with levels specifications, automatic merging should never be allowed. The fact that read.table automatically generates factors using default levels is why I nearly always import using as.is=TRUE, perform QC and combining of sources using strings, and only then convert to factor.

If you HAVE defined your factors using explicit levels definitions, you should have no trouble combining them.
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

Sam Steingold <sds at gnu.org> wrote:

>> * Bert Gunter <thagre.oregba at trar.pbz> [2012-10-17 23:21:44 -0700]:
>> However, Is level "5" in 'a' the same as level "5" in 'b' ?
>yes, of course.
>would anyone want to _different_ factors with identical string

More information about the R-help mailing list