On 16/11/2007, at 7:05 AM, carol white wrote:

> 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
>

        lapply(v,function(x){x[2]})

or

        unlist(lapply(v,function(x){x[2]}))

or (I can't resist)

        unlist(lapply(v,function(x,i){x[i]},i=2)) # For more flexibility.


                cheers,

                        Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@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.

Reply via email to