This question already has answers here:
Extract month and year from a zoo::yearmon object
(7个答案)
5年前关闭。
我有一个r数据集,其中包含这样的时间戳列表:
我想提取年份,但Posixct没有
有没有办法只获得2009年?
(7个答案)
5年前关闭。
我有一个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")