[R] Re: reading in columns of a data set as factors
Faheem Mitha
faheem at email.unc.edu
Thu Apr 27 05:58:22 CEST 2000
Dear people,
Replying to my own message here. The following appears to work. I read in
the data using read.table and then coerce the columns of the data frame to
factors afterwards.
clus.df <- read.table("clus.dat",header= FALSE, row.names=NULL,
col.names=names)
attach(clus.df)
for(i in 1:66)
clus.df[,i] <- as.factor(clus.df[,i])
However, I don't find this completely satisfactory. For one thing, I have
somehow got the impression that loops in Splus/R should be avoided
whenever possible (gee, I wonder where I got that impression) and so is
there a more elegant way to do this (without loops)?
Faheem.
On Wed, 26 Apr 2000, Faheem Mitha wrote:
> 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.
[stuff snipped]
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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