R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like:> mycols <- rep(NULL, 430) ; mycols[c(1:4)] <- NA > read.table(myfile, skip=2, colClasses=mycols)Any suggestions? Thanks in advance
rex.dwyer at syngenta.com
2011-Mar-15 17:11 UTC
[R] How to read only specified columns from a data file
I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab <- read.table(myfile, skip=2)[,1:5] -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Luis Ridao Sent: Tuesday, March 15, 2011 11:53 AM To: r-help at r-project.org Subject: [R] How to read only specified columns from a data file R-help, I'm trying to read a data file with plenty of columns. I just need the first 5 but it doe not work by doing something like:> mycols <- rep(NULL, 430) ; mycols[c(1:4)] <- NA > read.table(myfile, skip=2, colClasses=mycols)Any suggestions? Thanks in advance ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited.