0
a <- c("12/4/2010 9:30:00","12/4/2010 9:31:00","12/4/2010 9:32:00",
       "12/4/2010 9:33:00","12/4/2010 9:34:00","12/4/2010 9:35:00")
b <- strptime(a,"%d/%m/%Y %H:%M:%S")

> time(a)
[1] 1 2 3 4 5 6
attr(,"tsp")
[1] 1 6 1

> time(b)    
Error in hasTsp(x) : invalid time series parameters specified

> timeBased(a)
[1] FALSE

> timeBased(b)
[1] TRUE

有没有办法让它同时适用于timetimeBased函数,这意味着使用time和返回TRUE时没有错误timeBased

4

1 回答 1

1

time不做你认为它做的事。它是通用的,所以它根据你给它的对象类型做不同的事情,但一般来说,它给你索引,它与index

> require("xts")

> x <- xts(1:6, b)
> time(x)
[1] "2010-04-12 09:30:00 CDT" "2010-04-12 09:31:00 CDT"
[3] "2010-04-12 09:32:00 CDT" "2010-04-12 09:33:00 CDT"
[5] "2010-04-12 09:34:00 CDT" "2010-04-12 09:35:00 CDT"

> index(x)
[1] "2010-04-12 09:30:00 CDT" "2010-04-12 09:31:00 CDT"
[3] "2010-04-12 09:32:00 CDT" "2010-04-12 09:33:00 CDT"
[5] "2010-04-12 09:34:00 CDT" "2010-04-12 09:35:00 CDT"

> timeBased(x)
[1] FALSE
> timeBased(index(x))
[1] TRUE
> timeBased(time(x))
[1] TRUE
于 2012-04-17T13:40:26.077 回答