我有三个不同的数据框,包含不同长度的不同股票的价格,因为我必须删除异常值。每个数据框中的第一列始终是日期。
下一步是将每个数据框的不同列合并到一个列表中,特别是为了避免污染我的全局环境,因为我必须为每个股票价格执行相同的计算(日志返回等)。
这是输出。
head(Data)
A tibble: 6 x 11
DATE S1 S2 S3 S4 S5 S6 S7 S8 S9
<date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2000-12-29 55.313 31.508 44.74 34.90 20.00 6.8470 7.49 55.5 25.7216
2 2001-01-01 55.313 31.508 44.74 34.90 20.00 6.8470 7.49 55.5 25.7216
3 2001-01-02 54.131 31.508 44.41 34.22 20.00 6.7793 7.24 55.4 25.5093
4 2001-01-03 52.641 31.806 45.70 34.53 20.00 6.7401 7.24 54.2 25.2652
5 2001-01-04 55.720 32.403 47.60 35.24 19.72 6.6697 7.20 55.3 26.3055
6 2001-01-05 57.607 32.502 46.50 37.69 21.02 6.7740 7.18 55.5 27.6006
# ... with 1 more variables: S10 <dbl>
#Elimnate Outliers from stock 2,3,10 and created shortened df for stock 8
Data1 <- Data[-c(2042:2046), -c(4:10) ] ; # eliminate outliers and not affected stocks
Data2 <- Data[-c(2972:4241),c(1,8)]; #stock price ends before others and eliminate all other stocks
Data3 <- Data[,-c(2,3,7,11)] # Eliminate companies adjusted above
这是我试过的
Prices <- as.list(split(Data3,length(Data3)))
Prices <- append(split(Data1,length(Data1)),Prices)
Prices <- append(split(Data2,length(Data2)),Prices)
这给了我一个包含每个df的三个子列表的列表。但我想只将Data1,Data2和Data3的向量作为子列表。我的最终结果应该是10个子列表的列表(每个库存一个)。