Return values from a function in R
<p>Sometimes, after I wrote a function and called it, the result in the R studio console is the following:</p>

<pre><code>&gt; rankhospital("NC", "heart attack", "best")
</code></pre>

<p>Nothing is returned, and no error occured.</p>

<p>Code: </p>

<pre><code>rankhospital&lt;-function(state, outcome, num="best")
 {
  a&lt;-read.csv("outcome-of-care-measures.csv",na.string="Not Available")
  b&lt;-subset(a,a[,7]==state)

  if(outcome=="heart attack")
  {
   conv&lt;-as.numeric(b[,11])
   min_num&lt;-min(conv,na.rm = TRUE)
   min_row&lt;-which(b[,11]==min_num)
   hosname&lt;-b[min_row,2]
   hosname
  }

  if(outcome=="heart failure")
  {
   conv1&lt;-as.numeric(b[,17])
   min_num1&lt;-min(conv1,na.rm = TRUE)
   min_row1&lt;-which(b[,17]==min_num1)
   hosname1&lt;-b[min_row1,2]
   hosname1
  }

  if(outcome=="heart pneumonia")
   {
    conv2&lt;-as.numeric(b[,23])
    min_num2&lt;-min(conv2,na.rm = TRUE)
    min_row2&lt;-which(b[,23]==min_num2)
    hosname2&lt;-b[min_row2,2]
    hosname2
   }
}
</code></pre>

<p>The code is very simple. After user input state [,7] and outcome [,11],[,17],[,23], then to find the minimum outcome value for the state's outcome , then return the hospital name [,2] for the minimum outcome. </p>

<p>Which part is wrong? Thanks!</p>