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:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">