Re: [R] Basic question on concatenating factors

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Sat, 22 Nov 2008 13:38:51 -0200

You can try this also:

unlist(list(f1, f2))

On Fri, Nov 21, 2008 at 3:15 PM, udi cohen <ehudco_at_gmail.com> wrote:

> 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
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Sat 22 Nov 2008 - 15:41:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 22 Nov 2008 - 17:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive