title: How to extract the first and last 3 columns of a data frame in R
body: <p>I have some dataframes and I would like to extract the first 3 and the last 3 column from them separately. And the column names and the column amount of them are different. Could any one give me a tip that how can I do that? Thank you in advance ; )</p>
  
  <pre><code>df &lt;- matrix(sample(1:10, 100, replace = TRUE), 10)
  df &lt;- as.data.frame(df)
  #I know we can do something like this 
  df[,c(1:3,5:6)]
  #but I dont know how to select last 3 columns
  </code></pre>