I have this data frame with the single column date within a list of 200 elements that are also data frames and some of which contain variables other than the date.
list_dfs[[60]]
DATE
<chr>
1 2013-12-01
2 2013-12-02
3 2013-12-03
4 2013-12-04
5 2013-12-05
6 2013-12-06
7 2013-12-07
8 2013-12-08
9 2013-12-09
10 2013-12-10
# ... with 21 more rows
In another list, I have another data frame that also has only the date.
list_dfs_2[[60]]
DATE
<chr>
1 2013-12-01
2 2013-12-02
3 2013-12-03
4 2013-12-04
5 2013-12-05
6 2013-12-06
7 2013-12-07
8 2013-12-08
9 2013-12-09
10 2013-12-10
# ... with 21 more rows
Therefore, when I want to multiply the first data frame with the second one in a loop and save it in a list I get an error.
for(i in 1:200){
cbind(list_dfs[[i]][1], #save column date
list_dfs_2[[i]][-1]*list_dfs_2[[i]][-1]) -> new_list[[i]] # save the multiplication
}
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 31, 0
It stops and does not follow the loop, it saves only the multiplication up to 59, even if after that there are data frames that are not empty.
list_dfs[[61]]
# A tibble: 31 x 2
DATE BGA.CN
<chr> <dbl>
1 2014-03-01 0.4
2 2014-03-02 0.3
3 2014-03-03 0.9
4 2014-03-04 0.4
5 2014-03-05 0
6 2014-03-06 -0.0280
7 2014-03-07 0
8 2014-03-08 0.3
9 2014-03-09 0.2
10 2014-03-10 0
# ... with 21 more rows
I would like it to continue, how can I do it?