Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Which extraction method is the fastest?

$
0
0

Given list

li = list(a = list(b = list(1:3)))

the following extraction methods give identical result:

li[["a"]][["b"]][[1]][[2]]
[1] 2

purrr::pluck(li, "a", "b", 1, 2)
[1] 2

for (i in list("a", "b", 1, 2)) li = `[[`(li, i)
li
[1] 2

purrr::pluck and for have the obvious advantage that one can construct a vector of nested indices programmatically. Is there anything to consider when comparing them in terms of:

  • performance (eg. is the "chained"[[ method significantly different/faster from the for method?)
  • edge cases where one way might provide a different result from the others

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>