Converting a data frame to xts

后端 未结 9 919
暗喜
暗喜 2020-11-28 04:10

I\'m trying to convert a data frame to xts object using the as.xts()-method. Here is my input dataframe q:

q
                      t x  
1  2006-01-01 00:00:         


        
9条回答
  •  無奈伤痛
    2020-11-28 04:42

    I defined an index with the length equal to the number of rows of my tibble. Only after defining the time sequence separately as shown with the example:

    ti= seq(from = ymd_hm("2000-01-01 00:00"),
    to = ymd_hm("2000-01-02 01:00"), by =  "30 min", tz = "UTC")
    
    tbl <- tibble(t =ti,
        x = 1:length(t))
    )
    

    This code worked:

    xts.tbl <- xts(tbl[,-1], order.by = ti)
    

    However all data transformed into characters.

提交回复
热议问题