[R] get list index
Michael Bedward
michael.bedward at gmail.com
Fri Nov 26 04:22:20 CET 2010
Hello Lorezo,
Try this...
order(sapply(mylist, min))[1]
Michael
On 26 November 2010 11:23, Lorenzo Cattarino <l.cattarino at uq.edu.au> wrote:
> Hi R-users,
>
>
>
> I have a list
>
>
>
> mylist <- list(c(0.79, 0.92, 0.91, 0.86, 0.96, 0.96, 0.95, 0.94, 0.99),
> c(0.28, 0.45, 0.59, 0.69, 0.80, 0.87, 0.95, 0.94, 0.98), c(0.29, 0.39,
> 0.59, 0.69, 0.68, 0.80, 0.93, 0.95, 0.98))
>
>
>
> Is there a way to find the index of the list element that contains the
> lowest value among all the other elements? As the lowest value in each
> element is the first, the question is actually how to find the lowest
> 'first' values among the list elements, and then get the index of that
> element.
>
>
>
> In my example the list element would be (because the value is 0.28):
>
>
>
> [[2]]
>
> [1] 0.28 0.45 0.59 0.69 0.80 0.87 0.95 0.94 0.98
>
>
>
> and the position of course 2.
>
>
>
> I am looking for the index because I would like to subset the list
> afterwards (e.g. mylist[[2]]) and extract that element (i.e. the whole
> vector).
>
>
>
> Thanks for your help
>
> Lorenzo
>
>
>
> Lorenzo Cattarino
>
> PhD Candidate (Confirmed)
>
>
>
> Landscape Ecology and Conservation Group
>
> Centre for Spatial Environmental Research
>
> School of Geography, Planning and Environmental Management
>
> The University of Queensland
>
> Brisbane, Queensland, 4072, Australia
>
> Telephone 61-7-3365 4370, Mobile 0410884610
>
> Email l.cattarino at uq.edu.au
>
> Internet http://www.gpem.uq.edu.au/cser <http://www.gpem.uq.edu.au/cser>
>
>
>
>
>
> [[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