[R] Finding the Min.

Jarimatti Valkonen javalkon at hytti.uku.fi
Tue Jan 30 10:00:54 CET 2007


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



More information about the R-help mailing list