gpt4 book ai didi

r - 从 R 中的时间戳获取年份

转载 作者:行者123 更新时间:2023-12-01 09:54:58 24 4
gpt4 key购买 nike

我有一个 r 数据集,其中包含如下时间戳列表:2009-08-18 14:38:20 2010-08-10 14:58:25 等等

我想提取年份,但 Posixct 没有年份函数,不像 months(t$timestamp)

有没有办法只得到2009?

最佳答案

使用格式:

x <- as.POSIXct(c("2009-08-18 14:38:20", "2010-08-10 14:58:25"))
format(x, "%Y")

关于r - 从 R 中的时间戳获取年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30099544/

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