3

In accordance with the documentation of read.csv, colClasses argument:

Possible values are ..., "NULL" (when the column is skipped), ...

But looks like it doesn't work when col.names is used:

columnHeaders <- c("column1", "column2", "column_to_skip")
columnClasses <- c("factor", "factor", NULL)
data <- read.csv(fileCSV, header = FALSE, sep = ",", col.names = columnHeaders, colClasses = columnClasses)

In result data contains 3 columns, including column_to_skip. What is the proper way to read csv without this last column?

1
  • 1
    After you do this, check out how much easier it is with data.table::fread() Commented Mar 29, 2015 at 18:03

1 Answer 1

9

use "NULL" instead of NULL:

csv <- "1,2,3
4,5,6"
read.csv(text = csv, header = FALSE, colClasses = c("integer", "integer", "NULL"))
#   V1 V2
# 1  1  2
# 2  4  5
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.