From bill at insightful.com  Tue Nov 14 21:26:30 2006
From: bill at insightful.com (Bill Dunlap)
Date: Tue, 14 Nov 2006 12:26:30 -0800 (PST)
Subject: [Rd] c.factor
In-Reply-To: <Pine.LNX.4.64.0611141809050.25751@gannet.stats.ox.ac.uk>
References: <946928E281E8FD4B91D5B2CC3C91967D6AA9A0@lnex01.CONCORDIAFUNDS.COM>
	<1163526685.4492.20.camel@localhost.localdomain>
	<1163527030.4492.23.camel@localhost.localdomain>
	<Pine.LNX.4.64.0611141809050.25751@gannet.stats.ox.ac.uk>
Message-ID: <Pine.GSO.4.56.0611141218410.17778@durian.statsci.com>

On Tue, 14 Nov 2006, Prof Brian Ripley wrote:

> Well, R has managed without a factor method for c() for most of its decade
> of existence (not that it originally had factors as we know them).
>
> I would argue that factors are best viewed as an enumeration type, and
> anything which silently changes their level set is a bad idea.  I can see
> a case for a c() method for factors that combines factors with the same
> level sets, but I can also see this is best done by users who know the
> level sets are same (c.factor would have to expend a considerable effort
> to check).
>
> You also need to consider the dispatch rules.  c.factor will be called
> whenever the first argument is a factor, whatever the others are. S4 (I
> think, definitely S4-based versions of S-PLUS) has an alternative concat()
> that works differently (recursively) and seems a more natural model.

In addition, c() has always had a double meaning of
  (a) turning an object into a simple "vector" (an object
      without "attributes"), as in
      > c(factor(c("Cat","Dog","Cat")))
      [1] 1 2 1
      > c(data.frame(x=1:2,y=c("Dog","Cat")))
      $x
      [1] 1 2

      $y
      [1] Dog Cat
      Levels: Cat Dog

  (b) concatenating several such vectors into one.

The proposed c.factor does only (b).  Should we just
throw c() into the ash heap and use as.vector() or
concat() instead?

The whole concept of concatenating objects of disparate
types is suspect.

> On Tue, 14 Nov 2006, Marc Schwartz wrote:
>
> > On Tue, 2006-11-14 at 11:51 -0600, Marc Schwartz wrote:
> >> On Tue, 2006-11-14 at 16:36 +0000, Matthew Dowle wrote:
> >>> Hi,
> >>>
> >>> Given factors x and y,  c(x,y) does not seem to return a useful result :
> >>>> x
> >>> [1] a b c d e
> >>> Levels: a b c d e
> >>>> y
> >>> [1] d e f g h
> >>> Levels: d e f g h
> >>>> c(x,y)
> >>>  [1] 1 2 3 4 5 1 2 3 4 5
> >>>>
> >>>
> >>> Is there a case for a new method c.factor as follows?  Does something
> >>> similar exist already?  Is there a better way to write the function?

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."



[Rd] c.factor
Bill Dunlap