[R] Accessing the elements of a list
Thibaut Jombart
jombart at biomserv.univ-lyon1.fr
Fri Feb 1 12:18:04 CET 2008
Shubha Vishwanath Karanth wrote:
> Hi R,
>
>
>
> I wanted to know how do we access the elements of a list. In particular,
>
>
>
> v=list(c(1,2,3,4,5),c(1,2,33,4,5),c(1,2,333,4,5),c(1,2,3333,4,5))
>
>
>
> I want to access all the thirds items of the elements of the list. i.e.,
> I want to access the elements, 3,33,333,3333. This can be done through
> sapply as:
>
>
>
> sapply(v,function(x) x[3])
>
>
>
> But I need to access this without using 'sapply'. Like in a data frame,
> we do df[2,3] etc.... Any ideas?
>
>
Hi,
not the most elegant, but this works:
cmd > unlist(as.data.frame(v)[3,])
c.1..2..3..4..5. c.1..2..33..4..5. c.1..2..333..4..5.
c.1..2..3333..4..5.
3 33
333 3333
Cheers,
Thibaut.
--
######################################
Thibaut JOMBART
CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive
Universite Lyon 1
43 bd du 11 novembre 1918
69622 Villeurbanne Cedex
Tél. : 04.72.43.29.35
Fax : 04.72.43.13.88
jombart at biomserv.univ-lyon1.fr
http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en
http://pbil.univ-lyon1.fr/software/adegenet/
More information about the R-help
mailing list