[R] Subsetting Matrix

John Fox jfox at mcmaster.ca
Sat Sep 28 02:48:00 CEST 2002


Dear Kevin,

At 10:57 AM 9/28/2002 +1200, Ko-Kang Kevin Wang wrote:

>This is an easy question, however I cannot remember the exact command of
>doing it :-(
>
>Say I have a matrix:
>   > ff
>              [,1]      [,2]
>    [1,] 0.1000000 116.76987
>    [2,] 0.6444444 108.26811
>    [3,] 1.1888889  95.00240
>    [4,] 1.7333333 112.13647
>    [5,] 2.2777778 107.39893
>    [6,] 2.8222222 115.34615
>    [7,] 3.3666667  97.81029
>    [8,] 3.9111111 105.35119
>    [9,] 4.4555556 105.50052
>   [10,] 5.0000000 111.35761
>
>And I'd like to display the number in the first column, where its
>corresponding number is the minimum of the second column.
>
>In other words, I'd like to be able to extract out 1.1888889 from column
>1, as its correponding number in column 2 (95.00240) is the smallest in
>the column.

Try  ff[which.min(ff[,2]), 1].

John


-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list