R can't manage “General” formatted cells when

2019-09-03 15:38发布

I switched to libreoffice for my spreadsheets, but I noticed an error when importing an xls file modified with libreoffice inside R using the gdata package's read.xls() function. If a column is formatted as General, then once in R the cells display General instead of the right value.

To fix it I need to format every column to the proper format (number, text, etc), which i'd prefer to avoid since general better manage formatting (eg. automatically display the right number of significant digits).

Any better solution?

SOLVED:

After suggestion by RockScience I tried openxlsx:read.xlsx() and it works perfectly. Is even faster and less error prone than gdata:read.xls()!

1条回答
一夜七次
2楼-- · 2019-09-03 15:59

I have also noticed that gdata::read.xls doesn't evaluate the formula, but instead just imports what is displayed in excel. So for instance if a formula returns 1.0002 but in excel the display is limited to 2 digits, gdata::read.xls will only import 1.00

I have looked at several ways of importing xls data into R:

enter image description here

As you see gnumeric::read.gnumeric.sheet does evaluate the formula, so I suggest you try this (but it needs access to the gnumeric command line which is not available easily on Windows)

since recently there is also a new package http://cran.r-project.org/web/packages/openxlsx/index.html which seems very promissing.

查看更多
登录 后发表回答