I have a list that contains more lists of lists:
results <- sapply(c(paste0("cv_", seq(1:50)), "errors"), function(x) NULL)
## Locations for results to be stored
step_results <- sapply(c("myFit", "forecast", "errors"), function(x) NULL)
step_errors <- sapply(c("MAE", "MSE", "sign_accuracy"), function(x) NULL)
final_error <- sapply(c("MAE", "MSE", "sign_accuracy"), function(x) NULL)
for(i in 1:50){results[[i]] <- step_results}
for(i in 1:50){results[[i]][[3]] <- step_errors}
results$errors <- final_error
Now, in this whole structure, I would like to summarize all the values in sign_accuracyand store them inresults$errors$sign_accuracy
I could do this with for-loop, indexing with i:
sign_acc <- matrix(nrow = 50, ncol = 2)
for (i in 1:50){
sign_acc[i, ] <- `results[[i]][[3]][[3]]`
results$errors$sign_accuracy <- sign_acc
}
If I remember correctly, Matlab has something like list(:), which means all the elements. In Python, I saw something like list(0:-1), which also means all elements.
What is the elegant equivalent of R? I don't like cycles.
I have seen methods using the apply family of functions . Something like apply(data, "[[", 2), but can't make it work for deeper lists.