title: how to count the numbers based on two columns
body: <p>I have a data like this </p>
  
  <pre><code>df &lt;- structure(list(V1 = structure(c(2L, 4L, 4L, 2L, 4L, 4L, 4L, 4L, 
  1L, 1L, 1L, 1L, 3L, 2L, 2L, 4L, NA, 2L, 2L, 2L, 2L, 4L, 5L, 5L, 
  5L, NA, NA, 4L), .Label = c("", "1 x Bruit (U)", "1 x TAMAN (M)", 
  "2 x Bruit (U)", "2 x TIKIam(T)"), class = "factor"), V2 = structure(c(1L, 
  1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("BUX1_T10963", 
  "BUX1_T10964", "BUX1_T10965", "BUX1_T10966", "BUX2_T10076"), class = "factor")), .Names = c("V1", 
  "V2"), class = "data.frame", row.names = c(NA, -28L))
  </code></pre>
  
  <p>I try to make an example so that one can help me better </p>
  
  <p>The first two columns look like this </p>
  
  <p>1 x Bruit (U)   BUX1_T10963
  2 x Bruit (U)   BUX1_T10963
  2 x Bruit (U)   BUX1_T10963</p>
  
  <p>Here I want to know how many of the BUX1_T10963 has <code>Bruit (U)</code>and how many don't have. or has other thing or empty cell </p>
  
  <p>for example in example above, The answer is </p>
  
  <p>BUX1_T10963    has  5 Bruit (U)</p>
  
  <p>The output can look like below </p>
  
  <pre><code>                  BUX1_T10963      
  Bruit (U)               5
  NA                      0
  .                       0
  .                       0
  </code></pre>
  
  <p>@d.b gave an answer like </p>
  
  <pre><code>table(df$V1, df$V2)
  
                  BUX1_T10963 BUX1_T10964 BUX1_T10965 BUX1_T10966 BUX2_T10076
                            0           4           0           0           0
    1 x Bruit (U)           1           1           2           4           0
    1 x TAMAN (M)           0           0           1           0           0
    2 x Bruit (U)           2           4           1           1           1
    2 x TIKIam(T)           0           0           0           3           0
  </code></pre>
  
  <p>But it does not show how many empty assigned to them like the above format and also count the 2 different than 1</p>
  
  <pre><code>table(replace(gsub("(\\d x )", "", df$V1), is.na(df$V1), "NA"), df$V2)
  
              BUX1_T10963 BUX1_T10964 BUX1_T10965 BUX1_T10966 BUX2_T10076
                        0           4           0           0           0
    Bruit (U)           3           5           3           5           1
    NA                  0           0           1           2           0
    TAMAN (M)           0           0           1           0           0
    TIKIam(T)           0           0           0           3           0
  
  
  BUX1_T10963 should have 4 empty 
  BUX1_T10965 should have 1
  BUX1_T10966 should have 2
  </code></pre>
  
  <p>Is there a way to make it on the same raw?</p>