我POSIXlt
用来保持日期。我想要做的是按如下方式更改每个日期变量的月份,但它给出了一个错误。(下面d
是日期列表。)
> d
[1] "2012-02-01 UTC"
> a = sapply(d, function(x) { x$mday=14;})
Warning messages:
1: In x$mday = 14 : Coercing LHS to a list
2: In x$mday = 14 : Coercing LHS to a list
3: In x$mday = 14 : Coercing LHS to a list
4: In x$mday = 14 : Coercing LHS to a list
5: In x$mday = 14 : Coercing LHS to a list
6: In x$mday = 14 : Coercing LHS to a list
7: In x$mday = 14 : Coercing LHS to a list
8: In x$mday = 14 : Coercing LHS to a list
9: In x$mday = 14 : Coercing LHS to a list
> a
sec min hour mday mon year wday yday isdst
14 14 14 14 14 14 14 14 14
我意识到它改变了我的变量的格式。
> class(d)
[1] "POSIXlt" "POSIXt"
> a = sapply(d, function(x) { format(x, format = "%Y-%m-%d")})
> a
sec min hour mday mon year wday yday isdst
"0" "0" "0" "14" "1" "112" "0" "91" "0"
我该怎么做才能获得关注
> d
[1] "2012-02-14 UTC"
我试过format
,as.POSIXlt
等等方法。没有任何效果。