On my system >system.time(x1 <- sort(x,decreasing=TRUE)[1:1000]) user system elapsed 0.03 0.00 0.03
whereas > system.time(x1 <- x[order(x)][1:1000]) user system elapsed 0.11 0.00 0.11 I.e. using sort is about 30 times faster. Best regards Frede Aakmann Tøgersen Scientist UNIVERSITY OF AARHUS Faculty of Agricultural Sciences Dept. of Genetics and Biotechnology Blichers Allé 20, P.O. BOX 50 DK-8830 Tjele Phone: +45 8999 1900 Direct: +45 8999 1878 E-mail: [EMAIL PROTECTED] Web: http://www.agrsci.org This email may contain information that is confidential. Any use or publication of this email without written permission from Faculty of Agricultural Sciences is not allowed. If you are not the intended recipient, please notify Faculty of Agricultural Sciences immediately and delete this email. > -----Oprindelig meddelelse----- > Fra: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] På vegne af David Katz > Sendt: 12. november 2007 00:44 > Til: r-help@r-project.org > Emne: [R] Largest N Values Efficiently? > > > What is the most efficient alternative to x[order(x)][1:n] > where length(x)>>n? > I also need the positions of the mins/maxs perhaps by > preserving names. > > Thanks for any suggestions. > -- > View this message in context: > http://www.nabble.com/Largest-N-Values-Efficiently--tf4788033. > html#a13697535 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.