I have three different data frames containing prices of different stocks with different length, as I had to remove outliers. The first column in each dataframe is always the date.
The next step is to combine the different columns of each dataframe into one list, especially to avoid pollution of my global environment and as I have to perform the same calculations (log-returns, etc) for each stock price.
- How can I achieve this?
- Is it preferable to have always a combination of date and returns for each stock that should constituent the list?
Here is the output.
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
Here is what I have tried
Prices <- as.list(split(Data3,length(Data3)))
Prices <- append(split(Data1,length(Data1)),Prices)
Prices <- append(split(Data2,length(Data2)),Prices)
This gives me a list of three sublist, containing each df. But I would like to have only the vectors of Data1,Data2 and Data 3 as sublists. My final result should be list of 10 sublists (one for each stock).