title: Plotting by group in data.table
body: <p>I've got individual-level data for which I'm trying to summarize an outcome dynamically by group.</p>
  
  <p>Example:</p>
  
  <pre><code>set.seed(12039)
  DT &lt;- data.table(id = rep(1:100, each = 50),
                   grp = rep(letters[1:4], each = 1250),
                   time = rep(1:50, 100),
                   outcome = rnorm(5000))
  </code></pre>
  
  <p>I want to know the simplest way to plot the group-level summary, the data for which is contained in:</p>
  
  <pre><code>DT[ , mean(outcome), by = .(grp, time)]
  </code></pre>
  
  <p>I wanted something like:</p>
  
  <pre><code>dt[ , plot(mean(outcome)), by = .(grp, time)]
  </code></pre>
  
  <p>But this doesn't work at all.</p>
  
  <p>The workable option I am surviving on (which could be looped pretty easily) is:</p>
  
  <pre><code>plot(DT[grp == "a", mean(outcome), by = time])
  lines(DT[grp == "b", mean(outcome), by = time])
  lines(DT[grp == "c", mean(outcome), by = time])
  lines(DT[grp == "d", mean(outcome), by = time])
  </code></pre>
  
  <p>(with added parameters for colors, etc, excluded for conciseness)</p>
  
  <p>This strikes me as not the best way to do this--given <code>data.table</code>'s craft in handling groups, is there not a more elegant solution?</p>
  
  <p>Other sources have been pointing me to <code>matplot</code> but I can't see a straightforward way to use it--do I need to reshape <code>DT</code>, and is there a simple <code>reshape</code> that would get the job done?</p>