title: What does the error mean in a data.table with the function "seq" -- "The RHS length must either be 1 or match the LHS length exactly"?
body: <p>I am attempting to:</p>
  
  <ol>
  <li>calculate the difference in call duration between police units
  responding to the same call </li>
  <li>identify the longest duration among a group of calls with the same call ID</li>
  <li>arrange in descending order of duration</li>
  </ol>
  
  <p>My steps to do so are found in the code snippets below. </p>
  
  <p>First, I arrange in descending order by ID (multiple calls with the same ID) and then arrange within that by the call duration in hours (descending). </p>
  
  <p>Then, I make my data.frame into a data.table. </p>
  
  <p>Then, apply sequences (descending) by duration.</p>
  
  <p><code>call_duration_diff_by_unit[, duration_seq := seq(CALL_DURATION_HOURS), by = c("ID")]</code></p>
  
  <p>This is where the problem occurs: I get an error that says </p>
  
  <blockquote>
    <p>"Error in <code>[.data.table</code>(call_duration_diff_by_unit, , <code>:=</code>(duration_seq,  : 
      Supplied 2 items to be assigned to group 1 of size 1 in column 'duration_seq'. The RHS length must either be 1 (single values are ok) or match the LHS length exactly. If you wish to 'recycle' the RHS please use rep() explicitly to make this intent clear to readers of your code."</p>
  </blockquote>
  
  <p>The only explanation for this error I have found was specific to a unique package that I am not using. I understand the concept of "recycling" now, but not sure how it applies to this scenario... there aren't two vectors with different lengths.</p>
  
  <p>Could R be reading the <code>by = c("ID")</code> part incorrectly as a second input?</p>
  
  <pre><code>call_duration_diff_by_unit &lt;- cad_cfs_data %&gt;% 
    arrange(desc(ID), desc(CALL_DURATION_HOURS))
  
  call_duration_diff_by_unit &lt;- 
    data.table(call_duration_diff_by_unit)
  
  call_duration_diff_by_unit[, duration_seq := seq(CALL_DURATION_HOURS), by = c("ID")]
  
  </code></pre>
  
  <p>I expected it to make a unique numeric ID (assigning 1 to the longest duration) for each group of unique call IDs. Instead, I get the error and it doesn't save the variable "duration_seq" for use later down in the code.</p>