When i am using loop in R, for example
for (k in 1:length(bcd)) {
print(window(abc,start = (as.Date(start[i,]),end = (as.Date(finish[i,]))))
}
The outcome will be the the full selected data.
However, if i want to save the selected data, it only remember the data corresponding to last loop counter.
for (k in 1:length(bcd)) {
A = ???(window(abc,start = (as.Date(start[i,]),end = (as.Date(finish[i,]))))
}
What is the right function to use in “???” ? Thanks.
A list is the most general type. You could for instance initialize “A”:
The pros use
seq_along()instead of1:length(.)If they are all the same number of columns but different numbers of rows then this might work: