title: Subsetting a data frame with square brackets in R
body: <p>I am just starting with R, and ran into the following issue. </p>
  
  <p>Subsetting data frames with square brackets in the same way seems to result in either in a vector or in a data frame. Why is this difference? Below are the two data frames that I am trying to subset.</p>
  
  <p>First data frame <code>matching</code> that I subset with <code>matching[,1]</code>, which gives me a data frame with only one column. </p>
  
  <pre><code>&gt; attributes(matching)
  $names
  [1] "A" "B" "C" "D" "E" "F" "G" "H"
  
  $row.names
   [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  [50] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  
  $class
  [1] "tbl_df"     "tbl"        "data.frame"
  
  &gt; matching[,1]
  # A tibble: 67 x 1
         A
     &lt;int&gt;
   1     1
   2     2
   3     3
   4     4
   5     5
   6     6
   7     7
   8     8
   9     9
  10    10
  # ... with 57 more rows
  &gt; 
  </code></pre>
  
  <p>Second data frame <code>files</code> that I subset with <code>files[,1]</code> which gives me a vector</p>
  
  <pre><code>&gt; attributes(files)
  $names
  [1] "names"
  
  $row.names
   [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  [50] 50 51 52 53 54 55 56 57 58 59 60 61 62
  
  $class
  [1] "data.frame"
  
  &gt; files[,1]
   [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  [50] 50 51 52 53 54 55 56 57 58 59 60 61 62
  </code></pre>
  
  <p>The first was created with <code>read_excel</code> from excel files, and the second with <code>data.frame()</code> from a vector of character strings. </p>
  
  <p>Thank you!</p>