I have a nested list to record the results of my program:
- Each result has 2 vectors with varying lengths:
list(metric1=c(1, 2), metric2=c(12, 14, 0, 42))
- Each experiment consists of 100 iterations and therefore produces 100 of these results which I combine in another list together with the used settings (e.g. size, method, etc.).
list(size=25, method="random", list(metric1=c(...), metric2=c(...)), list(metric1=c(...), metric2=c(...), ...)
- To have a decent sample size, each experiment runs multiple times (e.g. 10 runs) and all of these results are collected in one big list. So the list with
size=25and `method="random" exists 10 times in that outer list.list(list(size=25, method="random", list(metric1=c(...), metric2=c(...)), list(size=25, method="random", list(metric1=c(...), metric2=c(...)), ..., list(size=100, method="min", list(metric1=c(...), metric2=c(...)))
Now my question: How do I actually access certain list across within that big list? For example:
- How do I select all lists where
size=25? - How do I get the first (nth) iteration of each list where
size=25andmethod="random"? - How do combine the 100
metric1vectors (1 for each iteration) wheresize=25andmethod="random"? - How would I plot the average length (of the 10 runs) of the
method2vector over the 100 iterations, wheresize=25andmethod="random"?
TL;DR: How do I access multiple elements from lists. With matrices, I use m[,3], but I just can't figure out how to do it with lists.
Thank you so much for your time and I would really appreciate any help on this!
Reproducible data:
How do I select all lists where size=25?
How do I get the first (nth) iteration ...
How do combine ...
... average length (of the 10 runs) of the
metric2...I don't know what you mean by "plot the average length" (just a scatterplot?), but it doesn't matter: extract in the same way you exacted Q3 and do what you need.