R 将不同数据帧的向量组合到一个列表中
我有三个不同的数据框,包含不同长度的不同股票的价格,因为我必须去除异常值。每个数据帧中的第一列始终是日期 下一步是将每个数据帧的不同列合并到一个列表中,特别是为了避免污染我的全球环境,因为我必须对每个股票价格执行相同的计算(日志返回等)R 将不同数据帧的向量组合到一个列表中,r,R,我有三个不同的数据框,包含不同长度的不同股票的价格,因为我必须去除异常值。每个数据帧中的第一列始终是日期 下一步是将每个数据帧的不同列合并到一个列表中,特别是为了避免污染我的全球环境,因为我必须对每个股票价格执行相同的计算(日志返回等) 我怎样才能做到这一点 对于应列入清单的每只股票,是否最好总是将日期和收益组合在一起 这是输出 head(Data) A tibble: 6 x 11 DATE S1 S2 S3 S4 S5 S6 S7 S8 S9
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
头部(数据)
一个tibble:6x11
日期S1 S2 S3 S4 S5 S6 S7 S8 S9
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
# ... 还有1个变量:S10
#从库存2,3,10中删除异常值,并为库存8创建缩短的df
你能提供一个可复制的例子吗?(输入、您尝试的代码和预期的输出)欢迎使用StackOverflow!请阅读相关信息以及如何给出建议。这将使其他人更容易帮助你。
Prices <- as.list(split(Data3,length(Data3)))
Prices <- append(split(Data1,length(Data1)),Prices)
Prices <- append(split(Data2,length(Data2)),Prices)