简体   繁体   English

R read_excel readxl有时会错误地将数字转换为日期

[英]R read_excel readxl sometimes incorrectly converts numbers to dates

When I use read_excel to import data from Excel to R, some numeric columns are automatically converted to dates. 当我使用read_excel将数据从Excel导入到R中时,某些数字列会自动转换为日期。

# e.g.
5600 to 1915-05-01

Is there a way to turn of this feature? 有没有办法启用此功能? Other than using "col_types" argument in read_excel. 除了在read_excel中使用“ col_types”参数之外。

The readxl package, like readr for raw data files, has a type guesser to determine how to read columns in an Excel spreadsheet. readxl包,像readr对于原始数据文件,有一个类型猜测器,以确定如何在Excel电子表格读取列。 As noted in the package vignette, the guessing process is not perfect, especially as it relates to date formats because they are stored as a special type of number. 如包装插图中所述,猜测过程并不完美,特别是因为它与日期格式有关,因为它们存储为特殊类型的数字。

在此处输入图片说明

As stated in the package documentation (as well as the comments on the OP), the way to avoid inaccurate guesses from the column type guesser is to explicitly specify the column types with the col_types argument on read_excel() . 如软件包文档中所述(以及对OP的注释),避免来自列类型猜测器的不正确猜测的方法是使用read_excel()上的col_types参数显式指定列类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM