title: Extracting unique values from data frame using R
body: <p>I have a data frame with multiple columns and I want to be able to isolate two of the columns and get the total amount of unique values... here's an example of what I mean:</p>
  
  <p>Lets say i have a data frame df:</p>
  
  <pre><code>df&lt;- data.frame(v1 = c(1, 2, 3, 2, "a"), v2 = c("a", 2 ,"b","b", 4))
  df
  
    v1 v2
  1  1  a
  2  2  2
  3  3  b
  4  2  b
  5  a  4
  </code></pre>
  
  <p>Now what Im trying to do is extract just the unique values over the two columns. So if i just used unique() for each column the out put would look like this:</p>
  
  <pre><code>&gt; unique(df[,1])
  [1] 1 2 3 a
  &gt; unique(df[,2])
  [1] a 2 b 4
  </code></pre>
  
  <p>But this is no good as it only finds the unique values per column, whereas I need the total amount of unique values over the two columns! For instance, 'a' is repeated in both columns, but I only want it counted once. For an example output of what I need; imagine the columns V1 and V2 are placed on top of each other like so:</p>
  
  <pre><code>  V1_V2
  1      1
  2      2
  3      3
  4      2
  5      a
  6      a
  7      2
  8      b
  9      b
  10     4
  </code></pre>
  
  <p>The unique values of V1_V2 would be:</p>
  
  <pre><code>   V1_V2
  1      1
  2      2
  3      3
  5      a
  8      b
  10     4
  </code></pre>
  
  <p>Then I could just count the rows using nrow().
  Any ideas how I'd achieve this?</p>