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? _________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 05/29/02 15:19, Matt Borkowski wrote:>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.I had this problem once. I solved it by moving one of the long lines of data to the beginning of the file, so it was the first record. Apparently R decided to get the number of columns from the first record. I just tried this with R 1.5.0 and it still works. If necessary you can make up a dummy line and delete it. -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._