user3563667
user3563667

Reputation: 293

R : How to select and extract specific columns using colClasses?

Using R, I want to read a large '.csv' file. To make it efficient ,I would like to read only the columns of interest by mentioning their index(indices) or column names and store the result in another variable.

I am using read.csv() function.

Upvotes: 1

Views: 1843

Answers (1)

James
James

Reputation: 66834

I suggest using read.csv.sql from the sqldf package. You use an SQL SELECT to filter the columns, eg:

read.csv.sql("file.csv", sql="SELECT col1, col2 FROM file")

SQLite handles the filtering, so you can load portions of files that would be too large otherwise.

Upvotes: 4

Related Questions