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

How to access specific named list inside nested list in R

$
0
0

I have the following nested list:

foo <- list(list(x = 1:10, y = 11:25), list(x = 1:10, y = 100:110))

It looks like this:

> foo
[[1]]
[[1]]$x
 [1]  1  2  3  4  5  6  7  8  9 10

[[1]]$y
 [1] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25


[[2]]
[[2]]$x
 [1]  1  2  3  4  5  6  7  8  9 10

[[2]]$y
 [1] 100 101 102 103 104 105 106 107 108 109 110

What I want to do is only to access the y part of the list yielding in the object that contain this:

 [[1]]
 [1] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25


[[2]]
 [1] 100 101 102 103 104 105 106 107 108 109 110

How can I achieve that?


Viewing all articles
Browse latest Browse all 204876

Trending Articles



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