title: R, count the occurrence of a variable like Excel PivotTable
body: <p>Wanted to count the occurrence of a variable in a data frame. It’s easy to do in Excel PivotTable and now learning how to do it in R.</p>
  
  <pre><code>      v_time visitor
  1/2/2018 16:07    Jack
  1/3/2018 16:09    Jack
  1/3/2018 16:12   David
  1/3/2018 16:16    Kate
  1/2/2018 16:21   David
  1/2/2018 16:32    Jack
  1/4/2018 16:33    Kate
  1/4/2018 16:55    Jack
  </code></pre>
  
  <p>Excel can make it easily like this:</p>
  
  <p><a href="https://i.stack.imgur.com/XeLzB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XeLzB.jpg" alt="enter image description here"></a></p>
  
  <p>I’ve tried some lines but still not getting there.</p>
  
  <pre><code>visitor &lt;- c("Jack", "Jack", "David", "Kate", "David", "Jack", "Kate", "Jack")
  v_time &lt;- c("1/2/2018 16:07","1/3/2018 16:09","1/3/2018 16:12","1/3/2018 16:16","1/2/2018 16:21","1/2/2018 16:32","1/4/2018 16:33", "1/4/2018 16:55")
  df &lt;- data.frame(v_time, visitor)
  
  as.Date(as.POSIXct(df$v_time, "%m/%d/%Y"))
  
  library(plyr)
  count(df$visitor, 'v_time')
  
  as.data.frame(table(df$visitor))
  </code></pre>
  
  <p>What’s the way to produce the Excel PivotTable alike output in R? Thank you.</p>