r - 在 R 中使用 int64 nanotimes 作为数组 dimnames
问题描述
我有一些可爱的纳米时代:
> mynames
[1] "2020-04-15T00:29:00.000000000+00:00" "2020-04-15T00:33:00.000000000+00:00"
我想将其作为暗名添加到我的数组中:
> a
[,1] [,2]
[1,] NA NA
[2,] NA NA
但是,它们似乎被转换为翻转字符串:
> dimnames(a)[1] <- list(values=mynames)
> a
[,1] [,2]
1.39309697650764e-202 NA NA
1.39315136717363e-202 NA NA
> dimnames(a)
[[1]]
[1] "1.39309697650764e-202" "1.39315136717363e-202"
如何将我的 dimname 分配保持为 nanotime/integer64s?或者,如果他们被迫将其字符化为暗名,我怎样才能至少防止它们成为不正确的数字字符串?
例如,您可以看到这些无法返回到合适的时间:
> nanotime(dimnames(a)[1][[1]][1])
Error in RcppCCTZ::parseDouble(x, fmt = format, tz = tz) :
Parse error on 1.39309697650764e-202
解决方案
的状态的文档被强制为. 要做所有基于to的强制返回和from ,你可以先强制你的to ,然后再强制to 。然后反向强制起作用:dimnames
value
character
nanotime
integer64
nanotime
integer64
character
library(nanotime)
mynames <- c(nanotime("2020-04-15T00:29:00.000000000+00:00"),
nanotime("2020-04-15T00:33:00.000000000+00:00"))
a <- array(NA, dim = c(2, 2))
# nanotime -> integer64 -> charachter
dimnames(a)[1] <- list(values = as.character(as.integer64(mynames)))
# character -> integer64 -> nanotime
nanotime(as.integer64(dimnames(a)[1][[1]][1]))
[1] "2020-04-15T00:29:00.000000000+00:00"
推荐阅读
- google-apps-script - 谷歌聊天机器人:两个人都看不到机器人回复
- sql - 列的 SUM SQL 函数
- python-3.x - Buildozer:ModuleNotFoundError:没有名为“yaml”的模块
- r - Fill NA while keeping continous scale
- autodesk-forge - 共享视图 + Forge 访问 - 我可以将 Inventor 模型作为共享视图推送,然后访问 Forge 应用程序中的存储桶
- php - 如何从维基百科 API 打印数据
- ruby-on-rails - heroku /api/comments:1 加载资源失败:服务器响应状态为 500
- apache-kafka - Confluent Controlcenter 上的架构无效
- typescript - 根据超类构造函数参数定义类型
- mysql - 服务器上的 I/O 进程限制正在过载