title: Frequency table with ddply function
body: <pre><code>ID&lt;-c("R1","R2","R2","R3","R3","R4","R4","R4","R4","R3","R3","R3","R3","R2","R2","R2","R5","R6")
  event&lt;-c("a","b","b","M","s","f","y","b","a","a","a","a","s","c","c","b","m","a")
  df&lt;-data.frame(ID,event)
  </code></pre>
  
  <p>How can I modify the below code to get this table. 2-How can i get the average of frequency for each element of frequency?for example: the average of frequency for a would be 1+3+1+1/4.</p>
  
  <pre><code>ddply(df,.(ID),summarise,N=sum(!is.na(ID)),frequency=length(event))
  
  ID  N   Number-event-level  levels       frequency
  R1  1      1                 a             a=1
  R2  5      2                 b,c         b=3,c=2
  R3  6      3                 M,a,s       M=1,a=3,s=2
  R4  4      4                 f,y,b,a    f=1,y=1,b=1,a=1
  R5  1      1                 m             m=1
  R6  1      1                 a             a=1 
  </code></pre>