[R] retaining character matrices when combining into data frames

Satoshi Takahama stakahama at ucsd.edu
Tue May 16 02:57:44 CEST 2006


Hello everyone,

If I want to convert or combine a (large) character matrix into a data
frame without having any of its columns convert into a factor class,
is there a simple solution? I() says it will operate on 'an
object' but it seems that unless the object is a vector, the results
are not what I expect. 

For instance, if g is a 2x2 character matrix, as.data.frame(I(g)) will
return an object of the data frame class but not structured in the way
I intended. What I hope to retrieve is the result of

h = data.frame(I(g[,1]),I(g[,2]))
names(h) = dimnames(g)[[2]]

With data sets of 100+ columns, wrapping I() around each column can be
very time-consuming when invoking the functions data.frame(), cbind(),
or as.data.frame(). R used to offer the optional argument, as.is=TRUE
(and S-PLUS offered stringsAsFactors=FALSE), to accomplish what this
task but it seems that this argument was removed some time ago. Is
there a more attractive alternative available now?

Thanks very much,

Satoshi


__________
Satoshi Takahama
Scripps Institution of Oceanography
Center for Atmospheric Science
9500 Gilman Drive, Dept. 0221
La Jolla, CA 92093
858-531-5328




More information about the R-help mailing list