ziggystar
ziggystar

Reputation: 28680

Read only explicitly named columns and skip others with read.table

I know that I can use colClasses to set some column types to NULL, and then those will be skipped.

What I really want is to have the default column class to be NULL. Then I can simply specify the columns I need by name colClasses(foo="numeric", bar="factor") and get only what I asked for.

Is there any way to achieve this without too much work to construct an appropriate colClasses vector?

Upvotes: 0

Views: 71

Answers (1)

konvas
konvas

Reputation: 14346

You can achieve this by using fread from the package data.table.

data <- fread("filename.csv", 
          select = c("foo", "bar"), 
          colClasses = c(foo="numeric", bar="factor"))

Upvotes: 2

Related Questions