title: Examples of drop in R
body: <p>How does <code>drop(df)</code> and <code>df[which1, which2, drop=T]</code> work? I can't find any examples...</p>
  
  <p>What I tried:</p>
  
  <pre><code>&gt; df = data.frame(a = rep(3,3), b = rep(3,3))
  &gt; df$a = as.factor(df$a)
  &gt; df$b = as.factor(df$b)
  &gt; 
  &gt; drop(df)
    a b
  1 1 3
  2 2 3
  3 3 3
  &gt; 
  &gt; df[,]
    a b
  1 1 3
  2 2 3
  3 3 3
  </code></pre>
  
  <p>Didn't drop anything (line 3 and column b both have one level). Any help's appreciated. Thanks.</p>
  
  <hr>
  
  <p>update: Thanks @Paul Hiemstra</p>
  
  <p>I realize it doesn't drop repeating data, but drops redundant dimensions</p>
  
  <pre><code>&gt; df[1, ]
    a b
  1 1 3
  &gt; dim( df[1, ] )
  [1] 1 2
  &gt; 
  &gt; df[ ,1]
  [1] 1 2 3
  Levels: 1 2 3
  &gt; dim( df[ ,1] )
  NULL
  </code></pre>
  
  <p>In above example, it seems R can't make <code>df[1, ]</code> a vector because there're columns a and b making the distinguish.
  R can make <code>df[ ,1]</code> a vector (dim=NULL)</p>