title: Keep column name when select one column from a data frame/matrix in R
body: <p>In R, when I select only one column from a data frame/matrix, the result will become a vector and lost the column names, how can I keep the column names?
  For example, if I run the following code,  </p>
  
  <pre><code>x &lt;- matrix(1,3,3)
  colnames(x) &lt;- c("test1","test2","test3")
  x[,1]
  </code></pre>
  
  <p>I will get</p>
  
  <pre><code>[1] 1 1 1
  </code></pre>
  
  <p>Actually, I want to get</p>
  
  <pre><code>     test1
  [1,]     1
  [2,]     1
  [3,]     1
  </code></pre>
  
  <p>The following code give me exactly what I want, however, is there any easier way to do this?</p>
  
  <pre><code>x &lt;- matrix(1,3,3)
  colnames(x) &lt;- c("test1","test2","test3")
  y &lt;- as.matrix(x[,1])
  colnames(y) &lt;- colnames(x)[1]
  y
  </code></pre>