[R] 1st el of a list of vectors

Richard M. Heiberger rmh at temple.edu
Tue Jul 22 06:10:27 CEST 2014


l = list(c(1,2), c(3,5,6), c(7))

sapply(l, `[`, 1)

On Mon, Jul 21, 2014 at 3:55 PM, carol white <wht_crl at yahoo.com> wrote:
> Hi,
> If we have a list of vectors of different lengths, how is it possible to retrieve the first element of the vectors of the list?
>
>
> l = list(c(1,2), c(3,5,6), c(7))
>
> 1,3,7 should be retrieved
>
> Thanks
>
> Carol
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list