title: Classify or cut dataframe by list of class range and summarize it with ddply
body: <p>I have question about ddply and subset.</p>
  
  <p>I have dataframe df like this : </p>
  
  <pre><code>df &lt;- read.table(textConnection(
  "   id v_idn v_seed v_time v_pop v_rank v_perco 
      1  15    125648 0      150   1      15      
      2  17    125648 0      120   2      5       
      3  18    125648 0      100   3      6       
      4  52    125648 0      25    4      1       
  
      5  17    125648 10     220   1      5      
      6  15    125648 10     160   2      15       
      7  18    125648 10     110   3      6      
      8  52    125648 10     50    4      1       
  
      9  56   -11152  0      250   1      17      
      10 15   -11152  0      180   2      15      
      11 18   -11152  0      110   3      6       
      12 22   -11152  0      5     4      14      
  
      13 56   -11152  10     250   1      17      
      14 15   -11152  10     180   2      15      
      15 22   -11152  10     125   3      14      
      16 18   -11152  10     120   4      6 "), header=TRUE)      
  </code></pre>
  
  <p><strong>STEP ONE :</strong> </p>
  
  <p>I have a list of equal interval with cut_interval like this : </p>
  
  <pre><code>myinterval &lt;- cut_interval(c(15,5,6,1,17,14), length=10)  
  </code></pre>
  
  <p>So i have two levels here : [0,10) and (10,20] </p>
  
  <p><strong>STEP TWO :</strong></p>
  
  <p>I want each group/class is define by my two levels in v_cut ... like this :</p>
  
  <pre><code>id v_idn v_seed v_time v_pop v_rank v_perco v_cut
  1  15    125648 0      150   1      15      (10,20]
  2  17    125648 0      120   2      5       [0,10)
  3  18    125648 0      100   3      6       [0,10)
  4  52    125648 0      25    4      1       [0,10)
  
  5  17    125648 10     220   1      5       [0,10)
  6  15    125648 10     160   2      15      (10,20] 
  7  18    125648 10     110   3      6       [0,10)
  8  52    125648 10     50    4      1       [0,10)
  
  9  56   -11152  0      250   1      17      (10,20]
  10 15   -11152  0      180   2      15      (10,20]
  11 18   -11152  0      110   3      6       [0,10)
  12 22   -11152  0      5     4      14      (10,20]
  
  13 56   -11152  10     250   1      17      (10,20]
  14 15   -11152  10     180   2      15      (10,20]
  15 22   -11152  10     125   3      14      (10,20]
  16 18   -11152  10     120   4      6       [0,10)
  </code></pre>
  
  <p><strong>STEP 3 :</strong></p>
  
  <p>I want to know the variability of v_rank for x axis, and time for y axis, for each group v_cut, so i need to compute min,mean,max,sd for v_rank value with something like </p>
  
  <pre><code>ddply(df, .(v_cut,v_time), summarize ,mean = mean(v_rank), min = min(v_rank), max = max(v_rank), sd = sd(v_rank))
  </code></pre>
  
  <p>*<em>RESULT WANTED : *</em></p>
  
  <pre><code>id  v_time MEAN.v_rank ... v_cut
  1   0      2.25            (10,20]
  2   0      2.42            [0,10)
  3   10     2.25            [0,10)
  4   10     2.42            (10,20]
  </code></pre>
  
  <p><strong>MY PROBLEM</strong> </p>
  
  <p>I don't know how to pass step 1 -> step 2 :/</p>
  
  <p>And if it's possible to group by v_cut like my example in step 3 ?</p>
  
  <p>Is there a possibility to make the same things with the "subset" option of ddply ? </p>
  
  <p>One more time, thanks a lot for your help great R guru !</p>
  
  <p><strong>UPDATE 1 :</strong></p>
  
  <p>I have an answer to go step1 to step2 : </p>
  
  <pre><code>df$v_cut &lt;- cut_interval(df$v_perco,n=10)
  </code></pre>
  
  <p>I'm using plyr, but there are perhaps a better answer in this case ?</p>
  
  <p>Answer to go to step 2 to step 3 ?</p>
  
  <p><strong>UPDATE 2 :</strong></p>
  
  <p>Brandon Bertelsen give me a good answer with melt + cast, but now (to understand) i want to make the same operation with plyr and ddply .. with a different result : </p>
  
  <pre><code>id  v_idn v_time MEAN.v_rank ... v_cut
      1   15   0      2.25            (10,20]
      2   15   10     2.45            (10,20]
      2   17   0      1.52            [0,10)
      2   17   10     2.42            [0,10)
      etc. 
  </code></pre>
  
  <p>I'm trying with something like this : </p>
  
  <pre><code>r('sumData &lt;- ddply(df, .(v_idn,v_time), summarize,min = min(v_rank),mean =  mean(v_rank), max = max(v_rank), sd=sd(v_rank))')
  </code></pre>
  
  <p>But i want to have v_cut in my sumData dataframe, how can i do with ddply ? is there an option to make this ? Or merging with initial df and key = v_idn to add column v_cut to sumData is the only good answer ?</p>