I have an 80 column Excel spreadsheet. I want to read only four of the columns. The position of the columns may change so I would like to select them by column name. I do this by
df <- read_xlsx("dat")[c("a", "b", "c", "d")]
However, d is guessed incorrectly as a logical while it is in fact a factor with four levels. The type of the columns can be set by col_type but the parameters of this function refer to the original 80 columns. Thus, to set the correct type, I would have to know the column position, which I do not. Even if, it seems cumbersome to set 80 column types (probably with rep()) although I only need four of them. Reading all as text does not work either because one column is in date:time format which gets scrambled by this. Does anyone have an idea how to solve this?
Packages with java and perl are not working on my computer.