r - Convert dates from XLS into R
问题描述
I import dates from Excel into R.
Some of the values appear as real numbers:
e.g. 43313.458055555559
I would like to convert these numbers into a
timestamp representation like this - 9/4/2018 11:45:35AM
Thanks in advance.
解决方案
根据 G. Grothendieck 的评论,尝试:
as.POSIXct(as.Date(43313.458055555559, origin = "1899-12-30"))
只需替换43313.458055555559
为DataFrame.name$Column.name
.
Windows PC 上的 Microsoft Excel 或 OpenOffice.org 等电子表格将日期时间表示为自 1899 年 12 月 30 日(通常)以来的天数和天数的分数。If
x
是此类数字的向量,as.Date("1899-12-30") + floor(x)
则将给出相对于 Date 的起源的 Date 类日期的向量。同样chron("12/30/1899") + x
将给出相对于 chron 起源的 chron 日期。Mac 上的 Excel 通常将日期表示为自 1904 年 1 月 1 日以来的天数和小数天数,as.Date("1904-01-01") + floor(x)
并将chron("01/01/1904") + x
表示此类日期的数字向量分别转换为 Date 和 chron。可以将 Excel 设置为使用任一来源,这就是上面通常使用该词的原因。
推荐阅读
- google-chrome - html5视频在谷歌浏览器上首次加载时无法搜索视频,但刷新页面几次后,它可以搜索
- java - 按值分组并分离输出
- php - 使用 JOIN 更新 MySQL 中的两个表
- c++ - 无法理解声明中的 const 结构
- android - 通过杰克逊解析具有多个元素的xml文件
- servicestack - 当我使用 ServiceStack.OrmLite.SqlServer Db.Select
有时 Result 是 TableB 的行或 TableA 的其他行 - html - Bootstrap 4 - 部分下一张幻灯片上的光滑滑块渐变效果
- java - 将 JSON 转换为对象抛出 JsonMappingException “无法反序列化类实例出 START_ARRAY 令牌”
- docker - ForgeRock 产品(即 AM、IDM、DS 和 IG)在 Docker 容器中使用的最佳操作系统是哪个?
- css - 我在 hompage 上的字体工作正常,但在其他页面上却没有