[Rd] c.factor

Bill Dunlap bill at insightful.com
Tue Nov 14 21:26:30 CET 2006


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."



More information about the R-devel mailing list