Hello, I have a data file (.csv) that has a size of about 2.6 GB. I am not able to read in the whole data set because of the memory limit. I actually only need some columns (3 columns) of the data set, is there a way to read in specified columns? I am using windows. Thanks, Julia -- View this message in context: http://www.nabble.com/how-to-read-in-only-some-columns-of-a-data-file-tp24081974p24081974.html Sent from the R help mailing list archive at Nabble.com.
Read the help page and the Import/Export Manual on the facilities offered by the colClasses parameter of the read.table function. On Jun 17, 2009, at 4:59 PM, liujb wrote:> > Hello, > > I have a data file (.csv) that has a size of about 2.6 GB. I am not > able to > read in the whole data set because of the memory limit. I actually > only need > some columns (3 columns) of the data set, is there a way to read in > specified columns? > > I am using windows.-- David Winsemius, MD Heritage Laboratories West Hartford, CT
Gabor Grothendieck
2009-Jun-17 21:33 UTC
[R] how to read in only some columns of a data file
read.csv.sql in sqldf will create an sqlite database on the fly, read the file in (without going through R) and then extract into R only that portion specified by an SQL statement. Alternately use read.csv with appropraite colClasses argument. On Wed, Jun 17, 2009 at 4:59 PM, liujb<liujulia7 at yahoo.com> wrote:> > Hello, > > I have a data file (.csv) that has a size of about 2.6 GB. I am not able to > read in the whole data set because of the memory limit. I actually only need > some columns (3 columns) of the data set, is there a way to read in > specified columns? > > I am using windows. > > Thanks, > Julia > -- > View this message in context: http://www.nabble.com/how-to-read-in-only-some-columns-of-a-data-file-tp24081974p24081974.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
Use the colClasses argument in combination with "NULL" for the columns you don't want to read. For example, this code reads the first column as character data and does not import the remaining 10 columns: yourdata<-read.csv("yourdata.csv",colClasses=c(rep("character",3),rep("NULL",10))) HTH, Mark Na On Wed, Jun 17, 2009 at 2:59 PM, liujb <liujulia7@yahoo.com> wrote:> > Hello, > > I have a data file (.csv) that has a size of about 2.6 GB. I am not able to > read in the whole data set because of the memory limit. I actually only > need > some columns (3 columns) of the data set, is there a way to read in > specified columns? > > I am using windows. > > Thanks, > Julia > -- > View this message in context: > http://www.nabble.com/how-to-read-in-only-some-columns-of-a-data-file-tp24081974p24081974.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]