Skip to content
Prev 308347 / 398506 Next

how to concatenate factor vectors?

:-)
ISTR reading in the R manual ~15(?) years ago that the language was in a
flux and one could not expect code written for the current release to
work in the next release.  I was considering R as the graphing back end
at that time, so this note turned me off.
Now it turns out that R has a legacy it cannot shake. :-)
Good! That's what I was looking for!

concatenate.factors <- function (x, y) {
  stopifnot(identical(levels(x),levels(y)))
  unlist(list(x,y), use.names=FALSE)
}

This seems to do what I need.

I see that
identical(levels(concatenate.factors(a,b)),levels(a))
==> TRUE
DIUC that concatenate.factors does NOT create an intermediate vector and
then re-factor it?

Thank you very much for your insight!
Message-ID: <874nlrahkt.fsf@gnu.org>
In-Reply-To: <E66794E69CFDE04D9A70842786030B93376BFA@PA-MBX04.na.tibco.com> (William Dunlap's message of "Thu, 18 Oct 2012 15:33:38 +0000")