Anthony
Anthony

Reputation: 169

R read.xlsx only specifying some columns ColClasses

I have an excel sheet with 50 columns.

How would I be able to only specify the colClass of a single attribute when using read.xlsx, without specifying the colClasses of all the attributes?

I tried

    read.xlsx(data.xlsx, colClasses=c("Test A"= "character"))

but receive the error message:

unused argument (colClasses = c("Test A" = "character"))

Thank you!

Upvotes: 0

Views: 1173

Answers (1)

Yuriy Barvinchenko
Yuriy Barvinchenko

Reputation: 1595

You can try read_xlsx() from readxl

library(readxl)
read_xlsx(data.xlsx, col_types=c("text"))

col_types vector can be populated with "guess" for all other columns.

More details about col_types:

Either NULL to guess all from the spreadsheet or a character vector containing one entry per column from these options: "skip", "guess", "logical", "numeric", "date", "text" or "list". If exactly one col_type is specified, it will be recycled. The content of a cell in a skipped column is never read and that column will not appear in the data frame output. A list cell loads a column as a list of length 1 vectors, which are typed using the type guessing logic from col_types = NULL, but on a cell-by-cell basis.

Upvotes: 1

Related Questions