尝试将特定功能应用于我的数据

时间:2019-05-02 17:48:01

标签: r

我正在遵循一个教程,并且试图在我的数据上应用某些功能。本教程下载数据的依据;

library(tidyquant)
library(tidyverse)
library(timetk)


symbols <- c("SPY","EFA", "IJS", "EEM","AGG")

prices <- 
  getSymbols(symbols, src = 'yahoo', 
             from = "2012-12-31",
             to = "2017-12-31",
             auto.assign = TRUE, warnings = FALSE) %>% 
  map(~Ad(get(.))) %>%
  reduce(merge) %>% 
  `colnames<-`(symbols)

wide格式返回的内容:

> head(prices)
                SPY      EFA      IJS      EEM      AGG
2012-12-31 125.8673 47.69352 73.92869 39.04684 95.47135
2013-01-02 129.0933 48.43166 75.95714 39.81280 95.35963
2013-01-03 128.8016 47.96195 75.85664 39.53108 95.11894
2013-01-04 129.3673 48.20519 76.45055 39.61031 95.22212
2013-01-07 129.0137 47.99550 76.00284 39.31097 95.17055
2013-01-08 128.6425 47.72708 75.71043 38.95880 95.25651

然后他们应用以下内容;

asset_returns_long <-  
  prices %>% 
  to.monthly(indexAt = "lastof", OHLC = FALSE) %>% 
  tk_tbl(preserve_index = TRUE, rename_index = "date") %>%
  gather(asset, returns, -date) %>% 
  group_by(asset) %>%  
  mutate(returns = (log(returns) - log(lag(returns)))) %>% 
  na.omit()

以长格式给出以下输出:

> head(asset_returns_long)
# A tibble: 6 x 3
# Groups:   asset [1]
  date       asset returns
  <date>     <chr>   <dbl>
1 2013-01-31 SPY    0.0499
2 2013-02-28 SPY    0.0127
3 2013-03-31 SPY    0.0373
4 2013-04-30 SPY    0.0190
5 2013-05-31 SPY    0.0233
6 2013-06-30 SPY   -0.0134

作者获取了数据,并对to.monthly数据进行了tk_tblwide并将其转换为long数据。

我也在尝试应用相同的功能,但是我的数据为long格式。我尝试将其转换为wide格式,但是名称重复。

我的问题是,如何直接在长数据上执行这些功能。我正在尝试的所有操作(转换为wide,grouping_by等均返回错误的结果)。

我正在使用的数据如下:

           ID         date         prc     
2015-06-02 "88250810" "2015-06-02" "55.250"
2015-06-02 "40414L10" "2015-06-02" "38.910"
2015-06-03 "88250810" "2015-06-03" "54.885"
2015-06-03 "40414L10" "2015-06-03" "38.240"
2015-06-04 "88250810" "2015-06-04" "53.980"
2015-06-04 "40414L10" "2015-06-04" "38.290"

该功能来自beow链接,可将每日价格转换为月度日志回报。

https://www.rdocumentation.org/packages/xts/versions/0.11-2/topics/to.period

设置为ts。     d <-as.xts(d,order.by = d $ date)

数据:

    data <- structure(c("88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"40414L10", "88250810", "40414L10", "88250810", "40414L10", "88250810", 
"88250810", "88250810", "2015-06-02", "2015-06-02", "2015-06-03", 
"2015-06-03", "2015-06-04", "2015-06-04", "2015-06-05", "2015-06-05", 
"2015-06-08", "2015-06-08", "2015-06-09", "2015-06-09", "2015-06-10", 
"2015-06-10", "2015-06-11", "2015-06-11", "2015-06-12", "2015-06-12", 
"2015-06-15", "2015-06-15", "2015-06-16", "2015-06-16", "2015-06-17", 
"2015-06-17", "2015-06-18", "2015-06-18", "2015-06-19", "2015-06-19", 
"2015-06-22", "2015-06-22", "2015-06-23", "2015-06-23", "2015-06-24", 
"2015-06-24", "2015-06-25", "2015-06-25", "2015-06-26", "2015-06-26", 
"2015-06-29", "2015-06-29", "2015-06-30", "2015-06-30", "2015-07-01", 
"2015-07-01", "2015-07-02", "2015-07-02", "2015-07-06", "2015-07-06", 
"2015-07-07", "2015-07-07", "2015-07-08", "2015-07-08", "2015-07-09", 
"2015-07-09", "2015-07-10", "2015-07-10", "2015-07-13", "2015-07-13", 
"2015-07-14", "2015-07-14", "2015-07-15", "2015-07-15", "2015-07-16", 
"2015-07-16", "2015-07-17", "2015-07-17", "2015-07-20", "2015-07-20", 
"2015-07-21", "2015-07-21", "2015-07-22", "2015-07-22", "2015-07-23", 
"2015-07-23", "2015-07-24", "2015-07-24", "2015-07-27", "2015-07-27", 
"2015-07-28", "2015-07-28", "2015-07-29", "2015-07-29", "2015-07-30", 
"2015-07-30", "2015-07-31", "2015-07-31", "2015-08-03", "2015-08-03", 
"2015-08-04", "2015-08-04", "2015-08-05", "2015-08-05", "2015-08-06", 
"2015-08-06", "2015-08-07", "2015-08-07", "2015-08-10", "2015-08-10", 
"2015-08-11", "2015-08-11", "2015-08-12", "2015-08-12", "2015-08-13", 
"2015-08-13", "2015-08-14", "2015-08-14", "2015-08-17", "2015-08-17", 
"2015-08-18", "2015-08-18", "2015-08-19", "2015-08-19", "2015-08-20", 
"2015-08-20", "2015-08-21", "2015-08-21", "2015-08-24", "2015-08-24", 
"2015-08-25", "2015-08-25", "2015-08-26", "2015-08-26", "2015-08-27", 
"2015-08-27", "2015-08-28", "2015-08-28", "2015-08-31", "2015-08-31", 
"2015-09-01", "2015-09-01", "2015-09-02", "2015-09-02", "2015-09-03", 
"2015-09-03", "2015-09-04", "2015-09-04", "2015-09-08", "2015-09-08", 
"2015-09-09", "2015-09-09", "2015-09-10", "2015-09-10", "2015-09-11", 
"2015-09-11", "2015-09-14", "2015-09-14", "2015-09-15", "2015-09-15", 
"2015-09-16", "2015-09-16", "2015-09-17", "2015-09-17", "2015-09-18", 
"2015-09-18", "2015-09-21", "2015-09-21", "2015-09-22", "2015-09-22", 
"2015-09-23", "2015-09-23", "2015-09-24", "2015-09-24", "2015-09-25", 
"2015-09-25", "2015-09-28", "2015-09-28", "2015-09-29", "2015-09-29", 
"2015-09-30", "2015-09-30", "2015-10-01", "2015-10-01", "2015-10-02", 
"2015-10-02", "2015-10-05", "2015-10-05", "2015-10-06", "2015-10-06", 
"2015-10-07", "2015-10-07", "2015-10-08", "2015-10-08", "2015-10-09", 
"2015-10-09", "2015-10-12", "2015-10-12", "2015-10-13", "2015-10-13", 
"2015-10-14", "2015-10-14", "2015-10-15", "2015-10-15", "2015-10-16", 
"2015-10-16", "2015-10-19", "2015-10-19", "2015-10-20", "2015-10-20", 
"2015-10-21", "2015-10-21", "2015-10-22", "2015-10-22", "2015-10-23", 
"2015-10-23", "2015-10-26", "2015-10-26", "2015-10-27", "2015-10-27", 
"2015-10-28", "2015-10-28", "2015-10-29", "2015-10-29", "2015-10-30", 
"2015-10-30", "2015-11-02", "2015-11-02", "2015-11-03", "2015-11-03", 
"2015-11-04", "2015-11-04", "2015-11-05", "2015-11-05", "2015-11-06", 
"2015-11-06", "2015-11-09", "2015-11-09", "2015-11-10", "2015-11-10", 
"2015-11-11", "2015-11-11", "2015-11-12", "2015-11-12", "2015-11-13", 
"2015-11-13", "2015-11-16", "2015-11-16", "2015-11-17", "2015-11-17", 
"2015-11-18", "2015-11-18", "2015-11-19", "2015-11-19", "2015-11-20", 
"2015-11-20", "2015-11-23", "2015-11-23", "2015-11-24", "2015-11-24", 
"2015-11-25", "2015-11-25", "2015-11-27", "2015-11-27", "2015-11-30", 
"2015-11-30", "2015-12-01", "2015-12-01", "2015-12-02", "2015-12-02", 
"2015-12-03", "2015-12-03", "2015-12-04", "2015-12-04", "2015-12-07", 
"2015-12-07", "2015-12-08", "2015-12-08", "2015-12-09", "2015-12-09", 
"2015-12-10", "2015-12-10", "2015-12-11", "2015-12-11", "2015-12-14", 
"2015-12-14", "2015-12-15", "2015-12-15", "2015-12-16", "2015-12-16", 
"2015-12-17", "2015-12-17", "2015-12-18", "2015-12-18", "2015-12-21", 
"2015-12-21", "2015-12-22", "2015-12-22", "2015-12-23", "2015-12-23", 
"2015-12-24", "2015-12-24", "2015-12-28", "2015-12-28", "2015-12-29", 
"2015-12-29", "2015-12-30", "2015-12-30", "2015-12-31", "2015-12-31", 
"2016-01-04", "2016-01-04", "2016-01-05", "2016-01-05", "2016-01-06", 
"2016-01-06", "2016-01-07", "2016-01-07", "2016-01-08", "2016-01-08", 
"2016-01-11", "2016-01-11", "2016-01-12", "2016-01-12", "2016-01-13", 
"2016-01-13", "2016-01-14", "2016-01-14", "2016-01-15", "2016-01-15", 
"2016-01-19", "2016-01-19", "2016-01-20", "2016-01-20", "2016-01-21", 
"2016-01-21", "2016-01-22", "2016-01-22", "2016-01-25", "2016-01-25", 
"2016-01-26", "2016-01-26", "2016-01-27", "2016-01-27", "2016-01-28", 
"2016-01-28", "2016-01-29", "2016-01-29", "2016-02-01", "2016-02-01", 
"2016-02-02", "2016-02-02", "2016-02-03", "2016-02-03", "2016-02-04", 
"2016-02-04", "2016-02-05", "2016-02-05", "2016-02-08", "2016-02-08", 
"2016-02-09", "2016-02-09", "2016-02-10", "2016-02-10", "2016-02-11", 
"2016-02-11", "2016-02-12", "2016-02-12", "2016-02-16", "2016-02-16", 
"2016-02-17", "2016-02-17", "2016-02-18", "2016-02-18", "2016-02-19", 
"2016-02-19", "2016-02-22", "2016-02-22", "2016-02-23", "2016-02-23", 
"2016-02-24", "2016-02-24", "2016-02-25", "2016-02-25", "2016-02-26", 
"2016-02-26", "2016-02-29", "2016-02-29", "2016-03-01", "2016-03-01", 
"2016-03-02", "2016-03-02", "2016-03-03", "2016-03-03", "2016-03-04", 
"2016-03-04", "2016-03-07", "2016-03-07", "2016-03-08", "2016-03-08", 
"2016-03-09", "2016-03-09", "2016-03-10", "2016-03-10", "2016-03-11", 
"2016-03-11", "2016-03-14", "2016-03-14", "2016-03-15", "2016-03-15", 
"2016-03-16", "2016-03-16", "2016-03-17", "2016-03-17", "2016-03-18", 
"2016-03-18", "2016-03-21", "2016-03-21", "2016-03-22", "2016-03-22", 
"2016-03-23", "2016-03-23", "2016-03-24", "2016-03-24", "2016-03-28", 
"2016-03-28", "2016-03-29", "2016-03-29", "2016-03-30", "2016-03-30", 
"2016-03-31", "2016-03-31", "2016-04-01", "2016-04-01", "2016-04-04", 
"2016-04-04", "2016-04-05", "2016-04-05", "2016-04-06", "2016-04-06", 
"2016-04-07", "2016-04-07", "2016-04-08", "2016-04-08", "2016-04-11", 
"2016-04-11", "2016-04-12", "2016-04-12", "2016-04-13", "2016-04-13", 
"2016-04-14", "2016-04-14", "2016-04-15", "2016-04-15", "2016-04-18", 
"2016-04-18", "2016-04-19", "2016-04-19", "2016-04-20", "2016-04-20", 
"2016-04-21", "2016-04-21", "2016-04-22", "2016-04-22", "2016-04-25", 
"2016-04-25", "2016-04-26", "2016-04-26", "2016-04-27", "2016-04-27", 
"2016-04-28", "2016-04-28", "2016-04-29", "2016-04-29", "2016-05-02", 
"2016-05-02", "2016-05-03", "2016-05-03", "2016-05-04", "2016-05-04", 
"2016-05-05", "2016-05-05", "2016-05-06", "2016-05-06", "2016-05-09", 
"2016-05-09", "2016-05-10", "2016-05-10", "2016-05-11", "2016-05-11", 
"2016-05-12", "2016-05-12", "2016-05-13", "2016-05-13", "2016-05-16", 
"2016-05-16", "2016-05-17", "2016-05-17", "2016-05-18", "2016-05-18", 
"2016-05-19", "2016-05-19", "2016-05-20", "2016-05-20", "2016-05-23", 
"2016-05-23", "2016-05-24", "2016-05-24", "2016-05-25", "2016-05-26", 
"2016-05-27", "55.250", "38.910", "54.885", "38.240", "53.980", 
"38.290", "53.785", "37.360", "52.820", "37.260", "52.915", "37.190", 
"54.190", "37.800", "53.640", "38.050", "53.010", "38.060", "53.045", 
"37.550", "53.090", "37.770", "53.290", "38.140", "54.220", "38.430", 
"54.510", "37.730", "55.500", "37.570", "54.830", "37.300", "53.990", 
"36.830", "53.795", "36.340", "52.900", "36.890", "51.520", "36.740", 
"51.510", "36.470", "51.910", "36.920", "51.970", "36.980", "51.390", 
"37.140", "51.210", "37.950", "49.530", "37.870", "48.110", "37.640", 
"49.010", "37.790", "49.330", "37.940", "49.760", "37.810", "49.490", 
"37.450", "49.360", "37.800", "49.360", "37.500", "50.090", "37.730", 
"50.230", "37.540", "49.300", "37.960", "50.510", "37.730", "49.030", 
"38.020", "49.030", "38.320", "50.080", "38.640", "49.960", "38.760", 
"50.240", "38.250", "49.980", "38.640", "50.090", "38.860", "49.840", 
"38.860", "50.855", "38.580", "50.250", "37.950", "50.320", "38.030", 
"52.080", "37.830", "50.640", "38.040", "51.110", "39.590", "50.630", 
"39.700", "50.640", "40.170", "50.900", "40.720", "49.910", "40.650", 
"49.200", "40.700", "47.430", "40.510", "45.960", "39.930", "44.890", 
"38.390", "43.520", "36.800", "45.410", "37.510", "47.060", "37.940", 
"47.990", "37.700", "47.840", "37.060", "46.340", "36.630", "47.350", 
"36.730", "47.460", "36.580", "46.530", "35.680", "48.690", "36.540", 
"47.610", "36.030", "47.410", "35.850", "47.570", "36.090", "47.830", 
"36.430", "48.300", "37.010", "48.700", "37.680", "48.150", "38.380", 
"47.800", "38.600", "47.450", "38.650", "46.610", "38.300", "46.580", 
"38.560", "46.750", "38.410", "47.170", "38.400", "46.950", "36.820", 
"47.530", "37.310", "49.520", "37.250", "48.440", "37.290", "48.770", 
"37.550", "50.130", "38.450", "50.460", "38.550", "51.040", "38.850", 
"51.520", "39.300", "50.870", "39.110", "51.340", "39.210", "50.910", 
"38.890", "52.650", "38.270", "52.430", "38.530", "52.570", "38.990", 
"52.640", "39.310", "52.430", "39.190", "51.900", "39.400", "58.090", 
"39.770", "58.980", "38.640", "58.810", "38.560", "58.420", "38.530", 
"58.670", "38.070", "56.570", "38.240", "56.720", "37.200", "56.990", 
"37.710", "57.150", "36.730", "56.950", "36.120", "57.400", "35.810", 
"57.630", "33.970", "57.210", "33.060", "57.030", "33.160", "57.600", 
"33.080", "56.670", "33.130", "56.130", "32.750", "56.875", "33.470", 
"57.070", "33.410", "57.960", "34.110", "57.950", "34.640", "58.120", 
"34.960", "57.350", "35.350", "57.850", "35.310", "57.270", "35.450", 
"57.550", "35.740", "58.120", "35.530", "58.310", "36.130", "57.550", 
"35.530", "57.690", "35.090", "58.880", "35.780", "58.350", "36.140", 
"57.670", "36.280", "56.760", "35.950", "56.930", "35.200", "56.210", 
"35.590", "56.220", "35.880", "57.550", "36.250", "58.070", "37.150", 
"56.530", "37.240", "54.940", "36.280", "55.820", "36.760", "55.610", 
"37.040", "56.700", "37.720", "56.750", "37.820", "56.420", "38.210", 
"57.020", "38.610", "56.160", "38.650", "54.810", "38.240", "54.340", 
"38.230", "53.770", "39.060", "53.420", "37.490", "51.700", "36.490", 
"50.360", "36.390", "51.210", "36.960", "51.530", "36.850", "49.820", 
"36.200", "50.030", "35.960", "48.030", "36.240", "48.220", "36.560", 
"49.010", "34.970", "49.830", "35.630", "50.300", "36.960", "50.080", 
"36.640", "50.700", "37.050", "50.670", "35.210", "51.130", "35.000", 
"52.930", "35.940", "52.830", "36.230", "50.640", "35.840", "50.250", 
"36.640", "51.260", "35.820", "49.880", "35.600", "50.900", "33.990", 
"50.680", "28.330", "50.750", "27.210", "50.380", "26.130", "51.140", 
"26.260", "52.540", "26.920", "53.690", "27.370", "53.060", "28.080", 
"52.760", "28.400", "53.300", "28.970", "52.240", "28.560", "52.460", 
"28.890", "53.110", "29.660", "53.300", "29.900", "53.020", "29.580", 
"54.220", "30.740", "54.420", "30.980", "54.870", "31.380", "54.890", 
"31.500", "55.490", "32.470", "54.530", "32.080", "54.750", "32.300", 
"55.490", "31.710", "56.060", "32.670", "55.610", "32.630", "55.730", 
"32.150", "56.140", "32.260", "56.600", "32.930", "57.090", "33.160", 
"57.020", "32.430", "56.900", "32.180", "56.600", "31.630", "56.700", 
"31.690", "56.520", "32.180", "57.410", "32.940", "58.370", "32.440", 
"57.420", "32.580", "57.940", "32.610", "57.720", "32.970", "57.710", 
"33.080", "58.360", "33.670", "57.150", "34.040", "57.890", "34.650", 
"57.820", "34.680", "58.440", "34.980", "59.170", "35.100", "59.220", 
"35.050", "58.930", "34.930", "58.950", "35.130", "58.420", "35.240", 
"59.050", "34.210", "58.860", "33.040", "58.680", "33.760", "59.020", 
"34.010", "59.400", "34.500", "59.920", "34.230", "58.690", "33.910", 
"57.040", "33.830", "57.850", "34.350", "57.200", "34.840", "56.430", 
"35.370", "56.640", "34.220", "57.200", "34.550", "56.910", "35.990", 
"57.630", "34.710", "57.630", "34.100", "57.160", "34.240", "57.120", 
"34.200", "58.020", "34.360", "57.430", "33.580", "58.010", "32.530", 
"57.230", "32.260", "58.530", "32.340", "58.730", "32.460", "60.090", 
"32.560", "60.440", "60.770", "61.020"), .Dim = c(499L, 3L), .Dimnames = list(
    NULL, c("ID", "date", "prc")), index = structure(c(1433203200, 
1433203200, 1433289600, 1433289600, 1433376000, 1433376000, 1433462400, 
1433462400, 1433721600, 1433721600, 1433808000, 1433808000, 1433894400, 
1433894400, 1433980800, 1433980800, 1434067200, 1434067200, 1434326400, 
1434326400, 1434412800, 1434412800, 1434499200, 1434499200, 1434585600, 
1434585600, 1434672000, 1434672000, 1434931200, 1434931200, 1435017600, 
1435017600, 1435104000, 1435104000, 1435190400, 1435190400, 1435276800, 
1435276800, 1435536000, 1435536000, 1435622400, 1435622400, 1435708800, 
1435708800, 1435795200, 1435795200, 1436140800, 1436140800, 1436227200, 
1436227200, 1436313600, 1436313600, 1436400000, 1436400000, 1436486400, 
1436486400, 1436745600, 1436745600, 1436832000, 1436832000, 1436918400, 
1436918400, 1437004800, 1437004800, 1437091200, 1437091200, 1437350400, 
1437350400, 1437436800, 1437436800, 1437523200, 1437523200, 1437609600, 
1437609600, 1437696000, 1437696000, 1437955200, 1437955200, 1438041600, 
1438041600, 1438128000, 1438128000, 1438214400, 1438214400, 1438300800, 
1438300800, 1438560000, 1438560000, 1438646400, 1438646400, 1438732800, 
1438732800, 1438819200, 1438819200, 1438905600, 1438905600, 1439164800, 
1439164800, 1439251200, 1439251200, 1439337600, 1439337600, 1439424000, 
1439424000, 1439510400, 1439510400, 1439769600, 1439769600, 1439856000, 
1439856000, 1439942400, 1439942400, 1440028800, 1440028800, 1440115200, 
1440115200, 1440374400, 1440374400, 1440460800, 1440460800, 1440547200, 
1440547200, 1440633600, 1440633600, 1440720000, 1440720000, 1440979200, 
1440979200, 1441065600, 1441065600, 1441152000, 1441152000, 1441238400, 
1441238400, 1441324800, 1441324800, 1441670400, 1441670400, 1441756800, 
1441756800, 1441843200, 1441843200, 1441929600, 1441929600, 1442188800, 
1442188800, 1442275200, 1442275200, 1442361600, 1442361600, 1442448000, 
1442448000, 1442534400, 1442534400, 1442793600, 1442793600, 1442880000, 
1442880000, 1442966400, 1442966400, 1443052800, 1443052800, 1443139200, 
1443139200, 1443398400, 1443398400, 1443484800, 1443484800, 1443571200, 
1443571200, 1443657600, 1443657600, 1443744000, 1443744000, 1444003200, 
1444003200, 1444089600, 1444089600, 1444176000, 1444176000, 1444262400, 
1444262400, 1444348800, 1444348800, 1444608000, 1444608000, 1444694400, 
1444694400, 1444780800, 1444780800, 1444867200, 1444867200, 1444953600, 
1444953600, 1445212800, 1445212800, 1445299200, 1445299200, 1445385600, 
1445385600, 1445472000, 1445472000, 1445558400, 1445558400, 1445817600, 
1445817600, 1445904000, 1445904000, 1445990400, 1445990400, 1446076800, 
1446076800, 1446163200, 1446163200, 1446422400, 1446422400, 1446508800, 
1446508800, 1446595200, 1446595200, 1446681600, 1446681600, 1446768000, 
1446768000, 1447027200, 1447027200, 1447113600, 1447113600, 1447200000, 
1447200000, 1447286400, 1447286400, 1447372800, 1447372800, 1447632000, 
1447632000, 1447718400, 1447718400, 1447804800, 1447804800, 1447891200, 
1447891200, 1447977600, 1447977600, 1448236800, 1448236800, 1448323200, 
1448323200, 1448409600, 1448409600, 1448582400, 1448582400, 1448841600, 
1448841600, 1448928000, 1448928000, 1449014400, 1449014400, 1449100800, 
1449100800, 1449187200, 1449187200, 1449446400, 1449446400, 1449532800, 
1449532800, 1449619200, 1449619200, 1449705600, 1449705600, 1449792000, 
1449792000, 1450051200, 1450051200, 1450137600, 1450137600, 1450224000, 
1450224000, 1450310400, 1450310400, 1450396800, 1450396800, 1450656000, 
1450656000, 1450742400, 1450742400, 1450828800, 1450828800, 1450915200, 
1450915200, 1451260800, 1451260800, 1451347200, 1451347200, 1451433600, 
1451433600, 1451520000, 1451520000, 1451865600, 1451865600, 1451952000, 
1451952000, 1452038400, 1452038400, 1452124800, 1452124800, 1452211200, 
1452211200, 1452470400, 1452470400, 1452556800, 1452556800, 1452643200, 
1452643200, 1452729600, 1452729600, 1452816000, 1452816000, 1453161600, 
1453161600, 1453248000, 1453248000, 1453334400, 1453334400, 1453420800, 
1453420800, 1453680000, 1453680000, 1453766400, 1453766400, 1453852800, 
1453852800, 1453939200, 1453939200, 1454025600, 1454025600, 1454284800, 
1454284800, 1454371200, 1454371200, 1454457600, 1454457600, 1454544000, 
1454544000, 1454630400, 1454630400, 1454889600, 1454889600, 1454976000, 
1454976000, 1455062400, 1455062400, 1455148800, 1455148800, 1455235200, 
1455235200, 1455580800, 1455580800, 1455667200, 1455667200, 1455753600, 
1455753600, 1455840000, 1455840000, 1456099200, 1456099200, 1456185600, 
1456185600, 1456272000, 1456272000, 1456358400, 1456358400, 1456444800, 
1456444800, 1456704000, 1456704000, 1456790400, 1456790400, 1456876800, 
1456876800, 1456963200, 1456963200, 1457049600, 1457049600, 1457308800, 
1457308800, 1457395200, 1457395200, 1457481600, 1457481600, 1457568000, 
1457568000, 1457654400, 1457654400, 1457913600, 1457913600, 1458000000, 
1458000000, 1458086400, 1458086400, 1458172800, 1458172800, 1458259200, 
1458259200, 1458518400, 1458518400, 1458604800, 1458604800, 1458691200, 
1458691200, 1458777600, 1458777600, 1459123200, 1459123200, 1459209600, 
1459209600, 1459296000, 1459296000, 1459382400, 1459382400, 1459468800, 
1459468800, 1459728000, 1459728000, 1459814400, 1459814400, 1459900800, 
1459900800, 1459987200, 1459987200, 1460073600, 1460073600, 1460332800, 
1460332800, 1460419200, 1460419200, 1460505600, 1460505600, 1460592000, 
1460592000, 1460678400, 1460678400, 1460937600, 1460937600, 1461024000, 
1461024000, 1461110400, 1461110400, 1461196800, 1461196800, 1461283200, 
1461283200, 1461542400, 1461542400, 1461628800, 1461628800, 1461715200, 
1461715200, 1461801600, 1461801600, 1461888000, 1461888000, 1462147200, 
1462147200, 1462233600, 1462233600, 1462320000, 1462320000, 1462406400, 
1462406400, 1462492800, 1462492800, 1462752000, 1462752000, 1462838400, 
1462838400, 1462924800, 1462924800, 1463011200, 1463011200, 1463097600, 
1463097600, 1463356800, 1463356800, 1463443200, 1463443200, 1463529600, 
1463529600, 1463616000, 1463616000, 1463702400, 1463702400, 1463961600, 
1463961600, 1464048000, 1464048000, 1464134400, 1464220800, 1464307200
), tzone = "UTC", tclass = "Date"), class = c("xts", "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC")

1 个答案:

答案 0 :(得分:1)

如果问题是如何从data创建一个宽幅时间序列,则这会从动物园对象z创建一个宽幅时间序列。您可以直接使用它,或者如果需要data.frame,请使用fortify.zoo(z),或者如果您需要xts对象,请使用as.xts(z)

library(zoo)
z <- read.zoo(data, index = "date", split = "ID")