R: Extracting the index of the final / last minimum value in a vector -


मेरे पास एक सदिश है

y & lt; -c (10: 1, c ( 0.10.1,0.1))

अगर मैं करता हूँ तो .min (y) , यह सूचकांक 11 देता है। हालांकि, मैं इसे अंतिम / अंतिम इंडेक्स वापस करना चाहता हूं, जहां न्यूनतम देखा गया है। मेरे पास ऐसा करने का अनाड़ी है, जो है:

rev (जो (y == न्यूनतम (y))) [1]

लेकिन

मैं सिर्फ अपना उपयोगिता फ़ंक्शन बनाऊँगा

< Pre> जो.min2 & lt; - फ़ंक्शन (x, last.index = FALSE, ...) {if (last.index) अधिकतम (जो (x == न्यूनतम (x, ...))) अन्य जो कि .min (x)} जो.min2 (y, TRUE) ## [1] 13 जो .min2 (y) ## [1] 11

यह भी काम करेगा अगर आप आपके वेक्टर में NA s है

  y & lt; - c (10: 1, c (0.1,0.1, एनए)) जो .min2 (y, TRUE, Na.rm = TRUE) ## [1] 12 जो .min2 (y, na.rm = TRUE) ## [1] 11  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -