[R] How to avoid automatic coercion to factor?
brahm at alum.mit.edu
Wed Sep 3 18:31:07 CEST 2003
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)
More information about the R-help