[R] Setting the Number of Columns

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed May 29 17:46:50 CEST 2002


"Matt Borkowski" <commnthght at hotmail.com> writes:

> I am trying to read in a data set with 17 columns into a data frame.
> The problem is, there are some lines in the data that occasionally pop
> up with less than 17 numbers in a row.  I was trying to use the command
> 
> data <- read.table("dataset.dat", fill=TRUE, quote = "")
> 
> There was no problem running this with an older version of R and the
> data was forced into a data frame with 17 columns with the missing
> data filled in as NA.  But after updating to the newest version
> something changed and now the data is being forced into a data frame
> with only 14 columns.
> 
> With the newest version of R is it possible to force the data into a
> data frame with user specified dimensions and fill in any missing data
> in a row with NA?

The number of columns are determined from the first five lines in the
file (some older version had a bug that caused the entire file to be
read instead). However, if column names are given, then they are used.
So how about this?:

cn <- paste("V",1:17,sep="")
data <- read.table("dataset.dat", fill=TRUE, quote = "", col.names=cn)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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