[R] how to extract the elements of a list of vectors in a fixed position?
Dimitris Rizopoulos
Dimitris.Rizopoulos at med.kuleuven.be
Thu Nov 15 20:53:03 CET 2007
try this:
v <- list(c(1,2), c(3,4), 5, c(-3:3))
sapply(v, "[", i = 2)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting carol white <wht_crl at yahoo.com>:
> Hi,
> How is it possible to extract athe elements of a list of vectors in
> a fixed position? suppose that I have a list of 2-element vectors,
> how can I extract the 2nd element of all vectors in the list? Can it
> be done with indexing and not by element name?
>
> Thanks
>
> carol
>
> So in this example, I want to extract 2 and 4
> v = list (c(1,2), c(3, 4))
>
>> v
> [[1]]
> [1] 1 2
>
> [[2]]
> [1] 3 4
>
>
>
>
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
> [[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.
>
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list