Hi, may be simle question, but a do not find it anywhere. Is there same function like max() ,but giving more results. max() give 1number-maximum I need funcion what give p bigest number. many thanks -- View this message in context: http://www.nabble.com/bigest-part-of-vector-tp22188901p22188901.html Sent from the R help mailing list archive at Nabble.com.
On Tue, 24 Feb 2009 11:36:06 -0800 (PST) (SO, 55 Chs 3175 YOLD) Peterko <lanikpeter at gmail.com> wrote:> > Hi, may be simle question, but a do not find it anywhere. > Is there same function like max() ,but giving more results. > max() give 1number-maximum > I need funcion what give p bigest number. > many thanksHow about sorting first? sort(vector,decreasing=TRUE)[1:p] -- Marius Glauser Life, loathe it or ignore it, you can't like it. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090224/55c33bce/attachment-0002.bin>
Dear Peter, Perhaps: set.seed(1) # For reproducibility p<-2 # Two biggest values of x x<-rnorm(10) tail(sort(x),p) [1] 0.7383247 1.5952808 In a function mode, foo<-function(x,p=2) tail(sort(x),p) foo(x,p=3) [1] 0.5757814 0.7383247 1.5952808 HTH, Jorge On Tue, Feb 24, 2009 at 2:36 PM, Peterko <lanikpeter@gmail.com> wrote:> > Hi, may be simle question, but a do not find it anywhere. > Is there same function like max() ,but giving more results. > max() give 1number-maximum > I need funcion what give p bigest number. > many thanks > -- > View this message in context: > http://www.nabble.com/bigest-part-of-vector-tp22188901p22188901.html > 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. >[[alternative HTML version deleted]]
There's probably something built in to R but you can change the values of the percentiles (p) below to get the value that corresponds to it. rounding might be problematic also. temp <- c(1,4,8,3,5) p <- 0.8 temp[order(temp)][round(length(temp)*p)] On Tue, Feb 24, 2009 at 2:36 PM, Peterko wrote:> Hi, may be simle question, but a do not find it anywhere. > Is there same function like max() ,but giving more results. > max() give 1number-maximum > I need funcion what give p bigest number. > many thanks > -- > View this message in context: > http://www.nabble.com/bigest-part-of-vector-tp22188901p22188901.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Thanks for all Peterko wrote:> > Hi, may be simle question, but a do not find it anywhere. > Is there same function like max() ,but giving more results. > max() give 1number-maximum > I need funcion what give p bigest number. > many thanks >-- View this message in context: http://www.nabble.com/bigest-part-of-vector-tp22188901p22189283.html Sent from the R help mailing list archive at Nabble.com.