gpt4 book ai didi

r - POSIXlt 组件的提取在 R 3.4.4 中运行良好,但在 R 3.5.0 中出现错误。为什么?

转载 作者:行者123 更新时间:2023-12-04 13:10:34 25 4
gpt4 key购买 nike

1) R 版本 3.4.4 (2018-03-15)

my.timedate <- as.POSIXlt('2016-01-01 16:00:00')  
# print(attributes(my.timedate))
print(my.timedate[['hour']])

[1] 16

2) R 版本 3.5.0 (2018-04-23)
my.timedate <- as.POSIXlt('2016-01-01 16:00:00')  
# print(attributes(my.timedate))
print(my.timedate[['hour']])

Error in FUN(X[[i]], ...) : subscript out of bounds

最佳答案

我认为这是 R 3.5.0 中的一个已知变化,其中 POSIXlt 的列表元素需要明确解包。使用 R 3.5.0:

edd@rob:~$ docker run --rm -ti r-base:3.5.0 \
R -q -e 'print(unclass(as.POSIXlt("2016-01-01 16:00:00")[["hour"]])'
> print(unclass(as.POSIXlt("2016-01-01 16:00:00"))[["hour"]])
[1] 16
>
>
edd@rob:~$

而 R 3.4.* 不需要 unclass()正如你所展示的:
edd@rob:~$ docker run --rm -ti r-base:3.4.3 \
R -q -e 'print(as.POSIXlt("2016-01-01 16:00:00")[["hour"]])'
> print(as.POSIXlt("2016-01-01 16:00:00")[["hour"]])
[1] 16
>
>
edd@rob:~$

我没有找到相应的新闻文件条目,所以不完全确定它是否是故意的......

编辑:正如其他人所指出的,相应的新闻条目有点不透明

* Single components of "POSIXlt" objects can now be extracted and
replaced via [ indexing with 2 indices.

关于r - POSIXlt 组件的提取在 R 3.4.4 中运行良好,但在 R 3.5.0 中出现错误。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50891475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com