title: Difference between data[ , "col"] and data$col
body: <p>From other answers on this site on similar questions, and e.g. from pages like <a href="http://www.r-tutor.com/r-introduction/data-frame/data-frame-column-vector" rel="nofollow">http://www.r-tutor.com/r-introduction/data-frame/data-frame-column-vector</a> , it seems that I extract a variable from a <code>data.frame</code>, <code>data[ , "col"]</code> and <code>data$col</code> should yield the same result. But now I have some data in Excel:</p>
  
  <pre><code>LU  Urban_LU    LU_Index    Urban_LU_index
  Residential Residential 2   0
  Rural residential   Residential 3   0
  Commercial  Commercial  4   1
  Public institutions including education Industrial  5   1
  Industry    Industrial  7   2
  </code></pre>
  
  <p>)</p>
  
  <p>and I read it with <code>read_excel</code> from the <code>readxl</code> package:</p>
  
  <pre><code>library(readxl)
  data &lt;- read_excel("data.xlsx", "Sheet 1")
  </code></pre>
  
  <p>Now I extract a single variable from the data frame, using <code>[</code> or <code>$</code>:</p>
  
  <pre><code>data[ , "LU"]
  # Source: local data frame [5 x 1]
  # 
  #                                        LU
  #                                     (chr)
  # 1                             Residential
  # 2                       Rural residential
  # 3                              Commercial
  # 4 Public institutions including education
  # 5                                Industry
  
  data$LU
  # [1] "Residential"                             "Rural residential"                      
  # [3] "Commercial"                              "Public institutions including education"
  # [5] "Industry"                               
  
  length(data[ , "LU"])
  # [1] 1
  length(data$LU)
  # [1] 5
  </code></pre>
  
  <p>Also, what I find suspicious are the classes of the data obtained from <code>read_excel</code> and the data which results from the two different modes of extraction:</p>
  
  <pre><code>class(data)
  # [1] "tbl_df"     "tbl"        "data.frame"
  
  class(data[ , "LU"])
  # [1] "tbl_df"     "data.frame"
  
  class(data$LU)
  # [1] "character"
  &gt; 
  </code></pre>
  
  <p>So what's the difference between <code>[ , "col"]</code> and <code>$col</code>? Am I missing something from the manuals or is this a special case? Also, what's with the <code>tbl_df</code> and <code>tbl</code> class identifiers? I suspect that they are the cause of my confusion, what do they mean?</p>