0
    row.names   Hospital                          State Heart Attack    Heart Failure
1   2275    PROVIDENCE MEMORIAL HOSPITAL            TX  16.1             9.1                 
2   2276    MEMORIAL HERMANN BAPTIST ORANGE HOSPITALTX  16.3            14.3       
4   2278    UNITED REGIONAL HEALTH CARE SYSTEM      TX  17.4            15.1    
5   2279    ST JOSEPH REGIONAL HEALTH CENTER        TX  15.7            15.6
6   2280    PARKLAND HEALTH AND HOSPITAL SYSTEM     TX  12.9            11.2    
7   2281    UNIVERSITY OF TEXAS MEDICAL BRANCH GAL  TX  17.4            11.8    

Hello R peeps,
I need to get a row.name where input, which is variable column name (Heart Attack or Heart Failure) is minimum for that column.

In the exmple above, if I input "Heart failure" it needs to return
[1] 2275
Which row name in the first row.

so far I got this:
inds<-subset(wfperstate, wfperstate[[outname]]==min)

where wfperstate is my data frame
outname is my input

Please, help!

Alex Kors
  • 182
  • 1
  • 4
  • 10
  • 3
    You should study more of the introductory texts available at CRAN. – IRTFM May 29 '14 at 00:49
  • `subset` is not recommended (at best, hard to use) for such a "non-interactive" mode, see http://stackoverflow.com/questions/9860090/in-r-why-is-better-than-subset – flodel May 29 '14 at 01:21

1 Answers1

1

To transform my last comment into a function :

get_min_rowname <- 
   function(dat,col)
     dat[which.min(dat[[col]]),"row.names"] 

Then you apply it :

get_min_rowname(wfperstate, "Heart Attack")
get_min_rowname(wfperstate, "Heart Failure")
thelatemail
  • 91,185
  • 12
  • 128
  • 188
agstudy
  • 119,832
  • 17
  • 199
  • 261