R list get first item of each element

Viewed 17789

This should probably be very easy for someone to answer but I have had no success on finding the answer anywhere.

I am trying to return, from a list in R, the first item of each element of the list.

> a
[1] 1 2 3
> b
[1] 11 22 33
> c
[1] 111 222 333
> d <- list(a = a,b = b,c = c)
> d
$a
[1] 1 2 3

$b
[1] 11 22 33

$c
[1] 111 222 333

Based on the construction of my list d above, I want to return a vector with three values:

return  1 11 111
2 Answers
Related