[R] Finding the Min.
Dear all R users, Suppose I have a dataset like that, data = 1 1.957759e-09 2 1.963619e-09 3 1.962807e-09 4 1.973951e-09 5 1.983401e-09 6 1.990894e-09 7 2.000935e-09 8 1.998391e-09 9 1.973322e-09 10 1.983202e-09 I want to see at which row minimum value of the second column occures. Therefore I made the following loop: i=1 while (min(data[,2]) != data[i,2]) { i = i+1 } i [1] 1 Is there any more effective way to do that in terms of time consumption? Thanks stat - Heres a new way to find what you're looking for - Yahoo! Answers [[alternative HTML version deleted]] __ 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.
Re: [R] Finding the Min.
?which.min Dear all R users, Suppose I have a dataset like that, data = 1 1.957759e-09 2 1.963619e-09 3 1.962807e-09 4 1.973951e-09 5 1.983401e-09 6 1.990894e-09 7 2.000935e-09 8 1.998391e-09 9 1.973322e-09 10 1.983202e-09 I want to see at which row minimum value of the second column occures. Therefore I made the following loop: i=1 while (min(data[,2]) != data[i,2]) { i = i+1 } i [1] 1 Is there any more effective way to do that in terms of time consumption? Thanks stat - Here's a new way to find what you're looking for - Yahoo! Answers [[alternative HTML version deleted]] * Confidentiality Note: The information contained in this mess...{{dropped}} __ 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.
Re: [R] Finding the Min.
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.