整洁的卷帘窗

时间:2019-02-17 12:51:29

标签: r dplyr

我想看看是否有人可以提供以下问题的完整版本(理想情况下是在管道中或不需要循环的内容中)。我正在尝试获取一个日期列,并从中提取一个嵌套列表,每个列表包含24个日期(顺序)。

library(tidyverse) 
library(lubridate) 
df <-read_csv("https://raw.githubusercontent.com/Nicktz/ExDat/master/extdata/findata.csv") %>% gather(Stock, Price, -Date) %>% 
filter(Date <= ymd(20070501)) %>% mutate(Ret = Price / lag(Price) - 1)

DateCol <- df %>% pull(Date) %>% unique

# Roll Window 
Roll_Window <- list()  
Min_Window <- 24

for( i in Min_Window:length(DateCol)){

  Roll_Window[c(i-Min_Window)+1] <-
    list(DateCol[c(i-Min_Window+1):i]) 
}

0 个答案:

没有答案
相关问题