Re: [R] Finding the Min.

From: Jarimatti Valkonen <javalkon_at_hytti.uku.fi>
Date: Tue 30 Jan 2007 - 09:00:54 GMT

stat stat wrote:

> I want to see at which row minimum value of the second column occures.
>
> Therefore I made the following loop:

[snip while-loop]

>
> Is there any more effective way to do that in terms of time consumption?

I don't know about timing, but I understand that loops are somewhat slow. Assuming that x is the first column and y is the second column:

	D <- data.frame( x = 1:10, y = rnorm(10) )
	D$x[ which.min(D$y) ]

See the help of which.min for more info.

-Jarimatti



R-help@stat.math.ethz.ch 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. Received on Tue Jan 30 20:09:15 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 30 Jan 2007 - 10:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.