How to Read Numeric Columns with read.xlsx2 in R

I like the xlsx package in R for its simplicity. However, I would always have a problem reading columns as numeric with the read.xlsx2 function. read.xlsx reads numeric columns properly, but it’s slow for large data sets.

By default, read.xlsx2 doesn’t guess the type of each column so it just reads everything as strings. It’s not immediately obvious from the documentation how to fix this without a bit of extra digging.

You actually have to look into the documentation of readColumns to see that if you pass colClasses=NA then it will guess the column type

So, use this: