Coerce xts to ts in R

后端 未结 5 1886
Happy的楠姐
Happy的楠姐 2021-01-07 02:54

I have xts time-series object for 10 days of data. The data is sampled at minutes frequency. Therefore, for each day, I have 1440 observations. I need to coerce

5条回答
  •  我在风中等你
    2021-01-07 03:28

    i think what you are looking for is the below:

    xts2ts <- function(XD) {
                 maxRow <- nrow(XD)
                 startYM <- c(.indexyear(XD[1]) + 1900, .indexmon(XD[1]) + 1L)
                 endYM <- c(.indexyear(XD[maxRow]) + 1900, .indexmon(XD[maxRow]) + 1L)
                 ts(as.numeric(XD), start = startYM, end = endYM, frequency = 12L)
    }
    

提交回复
热议问题