On Mar 15, 2011, at 1:11 PM, <rex.dw...@syngenta.com> wrote:
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org
] On Behalf Of Luis Ridao
Sent: Tuesday, March 15, 2011 11:53 AM
To: r-help@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)
I would have suggested:
mycols <- rep(NULL, 430) ; mycols[1:5] <- rep("numeric", 5)
inp <- read.table(myfile, skip=2, colClasses=mycols)
head(inp)
--
David.
Any suggestions?
Thanks in advance
______________________________________________
R-help@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.
______________________________________________
R-help@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.
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@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.