Skip to main content
added 23 characters in body
Source Link
Edward
  • 22.2k
  • 3
  • 18
  • 37

I have an Excel spreadsheet on my Desktop called my_data"my_data". I can recreate the spreadsheet in R as follows:

library(tibble); library(readxl) tibble(x = c(1L, 2L, 3L), y = c("A", "B", "C")) -> my_data 

On import, I can specify column types like this:

 read_excel("/Desktop/my_data.xlsx", col_types = c("numeric", "text") -> my_data 

But the vector supplied to col_types needcol_types needs to be in the same order as my spreadsheet to begive correct results. If I move the order of columns in the spreadsheet or add/delete columns, col_typescol_types will be wrong.

Can I supply the column types for specific columns and leave read_excel to guess the types for the rest of the columns?

I have an Excel spreadsheet on my Desktop called my_data. I can recreate the spreadsheet in R as follows:

library(tibble); library(readxl) tibble(x = c(1L, 2L, 3L), y = c("A", "B", "C")) -> my_data 

On import, I can specify column types like this:

 read_excel("/Desktop/my_data.xlsx", col_types = c("numeric", "text") -> my_data 

But the vector supplied to col_types need to be in the same order as my spreadsheet to be correct. If I move the order of columns in the spreadsheet or add/delete columns, col_types will be wrong.

Can I supply the column types for specific columns and leave read_excel to guess the types for the rest of columns?

I have an Excel spreadsheet called "my_data". I can recreate the spreadsheet in R as follows:

library(tibble); library(readxl) tibble(x = c(1L, 2L, 3L), y = c("A", "B", "C")) -> my_data 

On import, I can specify column types like this:

 read_excel("/Desktop/my_data.xlsx", col_types = c("numeric", "text") -> my_data 

But the vector supplied to col_types needs to be in the same order as my spreadsheet to give correct results. If I move the order of columns in the spreadsheet or add/delete columns, col_types will be wrong.

Can I supply the column types for specific columns and leave read_excel to guess the types for the rest of the columns?

Source Link
luciano
  • 14k
  • 37
  • 95
  • 136

Specify the column of types of only some variables when importing data with readxl::read_excel()

I have an Excel spreadsheet on my Desktop called my_data. I can recreate the spreadsheet in R as follows:

library(tibble); library(readxl) tibble(x = c(1L, 2L, 3L), y = c("A", "B", "C")) -> my_data 

On import, I can specify column types like this:

 read_excel("/Desktop/my_data.xlsx", col_types = c("numeric", "text") -> my_data 

But the vector supplied to col_types need to be in the same order as my spreadsheet to be correct. If I move the order of columns in the spreadsheet or add/delete columns, col_types will be wrong.

Can I supply the column types for specific columns and leave read_excel to guess the types for the rest of columns?