Benoit Chemineau
2007-Jul-03 14:12 UTC
[R] how to get the position of an element in a vector ?
Hi, dear R developers, I've got a vector of monthly volatilities and i would like to get the position of the highest volatility of the vector without computing a loop. Is there a function that could give me such a result ? a<-c(1,2,4,100,3) the highest value is the fourth of the vector. how can i get "4" without a loop going through the vector ? Thanks ! Benoit. [[alternative HTML version deleted]]
Henrique Dallazuanna
2007-Jul-03 14:26 UTC
[R] how to get the position of an element in a vector ?
which(a==max(a)) -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O On 03/07/07, Benoit Chemineau <benoitchemineau@gmail.com> wrote:> > Hi, dear R developers, > > I've got a vector of monthly volatilities and i would like to get the > position of the highest volatility of the vector without computing a loop. > Is there a function that could give me such a result ? > > a<-c(1,2,4,100,3) > > the highest value is the fourth of the vector. > how can i get "4" without a loop going through the vector ? > > Thanks ! > > Benoit. > > [[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. >[[alternative HTML version deleted]]
ONKELINX, Thierry
2007-Jul-03 14:30 UTC
[R] how to get the position of an element in a vector ?
?which.max ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney> -----Oorspronkelijk bericht----- > Van: r-help-bounces op stat.math.ethz.ch > [mailto:r-help-bounces op stat.math.ethz.ch] Namens Benoit Chemineau > Verzonden: dinsdag 3 juli 2007 16:12 > Aan: r-help op stat.math.ethz.ch > Onderwerp: [R] how to get the position of an element in a vector ? > > Hi, dear R developers, > > I've got a vector of monthly volatilities and i would like to > get the position of the highest volatility of the vector > without computing a loop. > Is there a function that could give me such a result ? > > a<-c(1,2,4,100,3) > > the highest value is the fourth of the vector. > how can i get "4" without a loop going through the vector ? > > Thanks ! > > Benoit. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help op 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. >