[R] How to avoid automatic coercion to factor?

Brian D Ripley ripley at stats.ox.ac.uk
Thu Sep 4 17:05:52 CEST 2003

Yes, that is one scenario and for that we need a better class
(possibly a better data.frame class).

But there are other scenarios for which a special class for the
column is better.  Which is why I asked.

> Steve Dutky <steve.dutky at thomson.com> wrote:
>> I have a function that manipulates a list of numeric and character
>> components of equal length and wants to return a data.frame.
>> ...
>> How can I get the columns Char1, Char2, (...CharN) returned coerced to
>> character and not factor?
> Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>> ... We should ask why you want character columns in a data frame?...
> I think Steve's situation is very common.  It points up a long-standing
> gap in the S language, namely a class of objects for tabular data that
> is less restrictive than data.frame or matrix.  Data frames are really
> designed for statistics (thus their inclination towards factors and
> valid column names), while matrices can only handle a single mode of
> data (numeric or character).
> In my own world, I've "implemented" this "class" as lists of
> equal-length vectors, and built many tools for it that mirror
> read.table, write.table, merge, cbind, rbind, etc.  Except that I've
> done it sloppily, without using real classes or
> constructors/validators/methods.
> It would be nice to have a real class "table" (maybe data.frame would
> extend it?).  But no, I'm not volunteering to build it. :-/
> --
>                               -- David Brahm (brahm at alum.mit.edu)

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list