Skip to content
Prev 308329 / 398506 Next

how to concatenate factor vectors?

hi Jorge,
is sort(unique()) really necessary?
I think
lev <- levels(a)
should be enough.

However, this does not quite do what I want.
I want a function which will _NOT_ have a non-factor vector as an
intermediate value because that would waste a LOT of memory in my case.
I want a function which will check that a and b have identical levels
(in Lisp lingo, the levels are EQ, not just EQUALP).

--8<---------------cut here---------------start------------->8---
[1] e e a b c e j d a b h i a e e g j a c e
Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
[1] d d f c j b d e j j g i g j j g g a j a b e d c b i i a b f
Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
[1]  5  5  1  2  3  5 10  4  1  2  8  9  1  5  5  7 10  1  3  5  4  4  6  3 10
[26]  2  4  5 10 10  7  9  7 10 10  7  7  1 10  1  2  5  4  3  2  9  9  1  2  6
[1] e e a b c e j d a b h i a e e g j a c e d d f c j b d e j j g i g j j g g a
[39] j a b e d c b i i a b f
Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
--8<---------------cut here---------------end--------------->8---

however, this is not a "direct" way (unlike my unlist(list(...))):
there is an intermediate integer vector c(a,b) which is mapped to a
character vector via letters, which is converted back to integers
(==factors).

IIUC, a factor is an integer vector which knows that the integers refer
to levels.

c(a,b) creates such an integer vector.
How do I tell it that it is a factor?
Message-ID: <87lif3akog.fsf@gnu.org>
In-Reply-To: <CAKL8G3FkyFJcKOrcRMJhVMUXc49t5dJXMJ1JVccuqbJBDMUuog@mail.gmail.com> (Jorge I. Velez's message of "Thu, 18 Oct 2012 16:43:58 +1100")