[R] reading in columns of a data set as factors

Faheem Mitha faheem at email.unc.edu
Thu Apr 27 04:38:23 CEST 2000

Dear people,

I've spent some time trying to find a simple way to do the following. I
can certainly think of complicated ways to do it...

I have a data set of 99 columns and 2000 rows. Each row corresponds to an
individual item of data, each column corresponds to a variable. I want
this data to be read into a data frame. The first 66 columns are binary,
values 0, 1, and I want these to be coerced into factor form. The last
33 are ordinary numeric data. For
concreteness let us call these variables b1... b66 and the last 33
x1... x33.

read.table does not seem to have any nice automated way of saying "I want
these n columns to correspond to factors". scan does, by going what =
(b1="", b2="", ...,b66="",... x1=0, x2=0,... ), and then I could coerce
the resulting list to a data frame, I suppose, but I had some problems
making a character vector of the correct form. I don't want to type 99
individual entries, and rep etc. have problems with equal signs and
inverted commas.

Maybe I am just going about this the wrong way. I am sure there must be
some simple way of doing this that I am overlooking.

                                 Sincerely, Faheem Mitha.

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list