title: subsetting data frame by row index
body: <p>Why is my last step converting the data frame to a vector? I want to keep the first 6000 observations in the data frame <code>key</code>.</p>
  
  <pre><code>  set.seed(1)
    key &lt;- data.frame(matrix(NA, nrow = 10000, ncol = 1))
    names(key) &lt;- "ID"
    key$ID &lt;- replicate(10000, 
                        rawToChar(as.raw(sample(c(48:57,65:90,97:122), 8, replace=T))))
    key &lt;- unique(key)  # still a data frame
    key &lt;- key[1:6000,] # no longer a data frame
  </code></pre>