openxlsx在检测日期时遇到问题 [英] openxlsx having problems with detect dates
问题描述
我正在使用软件包 openxlsx
将一个.xlsx文件打开到 R
中.这是我要读取的数据的基本示例:
I'm using the package openxlsx
to open a .xlsx file into R
. This is a basic example of the data I'm trying to read:
这是我用来阅读excel的代码:
This is the code I use to read the excel:
read.xlsx("F:/Test.xlsx",colNames = T,detectDates = T)
但是出现以下错误:
Error in read.xlsx.default("F:/Test.xlsx", colNames = T, detectDates = T) :
basic_string::substr: __pos (which is 8) > this->size() (which is 2)
如果我删除excel的第一行,我会不断收到相同的错误.它的确连接好了,因为上次我运行脚本(2周前)时,Excel是相同的格式,但没有出现此错误,也没有更新R或Rstudio或软件包.
If I delete the first row of the excel I keep getting the same error. And it's really wired because the last time I run the script (2 weeks ago) the Excel was in the same format and I didn't get this error and I haven't updated R or Rstudio or the package.
推荐答案
解决此问题的另一种方法可能是在没有 detectDates = TRUE
的情况下读取数据,并将其放入R-工作空间中,因此请使用 xlsx
函数: convertToDate
转换那些包含日期的列(将被读取为双精度).
An alternative to solve this issue might be to read your data without detectDates=TRUE
and once you have it in your R- workspace, accordingly convert those columns that include dates (which will be read as doubles) using xlsx
function: convertToDate
.
这篇关于openxlsx在检测日期时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!