Re: [R] get list index
Try this: which.min(sapply(mylist, min)) On Thu, Nov 25, 2010 at 10:23 PM, Lorenzo Cattarino l.cattar...@uq.edu.auwrote: 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.cattar...@uq.edu.au Internet http://www.gpem.uq.edu.au/cser http://www.gpem.uq.edu.au/cser [[alternative HTML version deleted]] __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ 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.
[R] get list index
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.cattar...@uq.edu.au Internet http://www.gpem.uq.edu.au/cser http://www.gpem.uq.edu.au/cser [[alternative HTML version deleted]] __ 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.
Re: [R] get list index
Hello Lorezo, Try this... order(sapply(mylist, min))[1] Michael On 26 November 2010 11:23, Lorenzo Cattarino l.cattar...@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.cattar...@uq.edu.au Internet http://www.gpem.uq.edu.au/cser http://www.gpem.uq.edu.au/cser [[alternative HTML version deleted]] __ 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. __ 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.