title: Looping through an array and assigning value to vector giving NULL incorrect value
body: <p>I have a vector called "states" with all states 2 letters abbreviations, and a temp1 dataframe with 3 columns "Hospital.Name", "heart attack" and "State"</p>
  
  <pre><code>temp1   Hospital.Name                     heart attack State
  99      PROVIDENCE ALASKA MEDICAL CENTER        13.4    AK
  103     ALASKA REGIONAL HOSPITAL                14.5    AK
  102     FAIRBANKS MEMORIAL HOSPITAL             15.5    AK
  </code></pre>
  
  <p>temp1 table has many more hospitals for every state</p>
  
  <pre><code>states
   [1] "AK" "AL" "AR" "AZ" "CA" "CO" "CT" "DC" "DE" "FL" "GA" "GU" "HI" "IA" "ID" "IL" "IN" "KS" "KY" "LA" "MA" "MD" "ME" "MI" "MN" "MO" "MS"
  [28] "MT" "NC" "ND" "NE" "NH" "NJ" "NM" "NV" "NY" "OH" "OK" "OR" "PA" "PR" "RI" "SC" "SD" "TN" "TX" "UT" "VA" "VI" "VT" "WA" "WI" "WV" "WY
  </code></pre>
  
  <p>When I run this code by itself with the first value of the "states" array I get a correct result</p>
  
  <pre><code>resulttest &lt;- subset(temp1[1,], State ==states[1])
  resulttest
  
     Hospital.Name                     heart attack State
  99 PROVIDENCE ALASKA MEDICAL CENTER         13.4    AK
  </code></pre>
  
  <p>But when I try to run this on a loop for all states in the "state" vector i get a NULL value</p>
  
  <pre><code>for (i in 1:length(states)){
       resulttest &lt;- subset(temp1[1,], State ==states[i])
       }
  
  # &gt; resulttest
  #
  # [1] Hospital.Name heart attack  State        
  # &lt;0 rows&gt; (or 0-length row.names)
  </code></pre>
  
  <p>Can somebody help me with the loop function?, Thanks</p>