[R] Basic question on concatenating factors
udi cohen
ehudco at gmail.com
Fri Nov 21 18:15:19 CET 2008
Hi all,
I hope it's not too trivial for the list - I'm trying to concatenate
two factor arrays, and obtain the following:
> f1<-factor(c("a","a","b"))
> f1
[1] a a b
Levels: a b
> f2<-factor(c("b","b","a"))
> f2
[1] b b a
Levels: a b
> c(f1,f2)
[1] 1 1 2 2 2 1
Instead of getting:
[1] a a b b b a
Levels: a b
a related question is: how do I add a level which does not exists yet
in a factored vector, so I'll be able to add later these values,
without getting:
In `[<-.factor`(`*tmp*`, 2, value = "c") :
invalid factor level, NAs generated
Thanks,
EC
More information about the R-help
mailing list