From pburns at pburns.seanet.com  Thu Feb  4 17:45:21 2010
From: pburns at pburns.seanet.com (Patrick Burns)
Date: Thu, 04 Feb 2010 16:45:21 +0000
Subject: [Rd] Why is there no c.factor?
In-Reply-To: <f8e6ff051002040753x33282f33l78fce9f98dc29ae8@mail.gmail.com>
References: <f8e6ff051002040753x33282f33l78fce9f98dc29ae8@mail.gmail.com>
Message-ID: <4B6AF9A1.4080605@pburns.seanet.com>

The argument I have in 'The R Inferno'
is that how you want to combine factors
may differ from someone else's desires.

There are lots of tricky questions:
What about ordered factors?
What if the ordered levels are different in
different objects?
...

Pat


On 04/02/2010 15:53, Hadley Wickham wrote:
> Hi all,
>
> Is there are reason that there is no c.factor method?  Analogous to
> c.Date, I'd expect something like the following to be useful:
>
> c.factor<- function(...) {
>    factors<- list(...)
>    levels<- unique(unlist(lapply(factors, levels)))
>    char<- unlist(lapply(factors, as.character))
>
>    factor(char, levels = levels)
> }
>
> c(factor("a"), factor("b"), factor(c("c", "b","a")), factor("d"))
> # [1] a b c b a d
> # Levels: a b c d
>
> Hadley
>

-- 
Patrick Burns
pburns at pburns.seanet.com
http://www.burns-stat.com
(home of 'The R Inferno' and 'A Guide for the Unwilling S User')



[Rd] Why is there no c.factor?
Patrick Burns