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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._