Wensui Liu
2009-May-03 17:36 UTC
[R] is there a way to read a specific column from a txt file
Sometimes, it is too costly to read the whole data file into R. I am looking for solution in scan() and read.Lines() but don't they work. Thank you so much! -- =============================WenSui Liu Acquisition Risk, Chase Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller
Gabor Grothendieck
2009-May-03 17:56 UTC
[R] is there a way to read a specific column from a txt file
The sqldf package can read in a column without reading the entire file into R. It will automatically set up a database for you read the file into the database (all this without going through R) and then it will extract the column you want. You will need two statements. One to define which file to use and one to read in the file and extract the column. See example 6b on the sqldf home page: http://sqldf.googlecode.com On Sun, May 3, 2009 at 1:36 PM, Wensui Liu <liuwensui at gmail.com> wrote:> Sometimes, it is too costly to read the whole data file into R. > I am looking for solution in scan() and read.Lines() but don't they work. > Thank you so much! > -- > =============================> WenSui Liu > Acquisition Risk, Chase > Blog ? : statcompute.spaces.live.com > > Tough Times Never Last. But Tough People Do. ?- Robert Schuller > > ______________________________________________ > 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. >
Paul Smith
2009-May-03 18:15 UTC
[R] is there a way to read a specific column from a txt file
On Sun, May 3, 2009 at 6:36 PM, Wensui Liu <liuwensui at gmail.com> wrote:> Sometimes, it is too costly to read the whole data file into R. > I am looking for solution in scan() and read.Lines() but don't they work.Try the following (assuming a 3 columns data file): mydata <- read.table(file="myfile",header=T,colClasses=c(NA,"NULL",NA)) "NULL" indicates the column to be omitted. Hope this helps you, Paul