title: Map() function for calculating the difference in months in data - data.table in R
body: <p>I cannot figure out why this part of code is getting an error: </p>
  
  <pre><code>claimsData[, monthOfClaim := lengths(Map(seq, fromdate, clDate, by = "months"))]
  
  
  Error in seq.int(r1$mon, 12 * (to0$year - r1$year) + to0$mon, by) : 
    wrong sign in 'by' argument
  </code></pre>
  
  <p>It is working for another data.table of the same format, but seems to throw an error here. What does this error mean and how can it be avoided? Maybe an alternative approach for counting the number of months between the two dates?</p>
  
  <p>DATA: </p>
  
  <pre><code>&gt;   dput(claimsData[1:20,])
  structure(list(clientID = c("1012643-G000809-000-RB250-2014-07-01-2014-07-01-1972-04-09", 
  "RB250-7356", 
  "RB250-2967", 
  "RB250-249", 
  "RB250-2305", 
  "RB250-8884", 
  "RB250-3906", 
  "1017546", 
  "1018207", 
  "1018207-423", 
  "1018207-5746", 
  "1018207-543", 
  "1018207-8765", 
  "1019031-7654", "1025828", 
  "102990", 
  "103018-01-01-6",
  "10300-01-6", 
  "103001-6", "1030"
  ), clDate = structure(c(16471, 16268, 16419, 16450, 16312, 16277, 
  16422, 17073, 16293, 16304, 16440, 16455, 16855, 16461, 16115, 
  16209, 17825, 17821, 17749, 17781), class = "Date"), amount = c(8865, 
  7434396.85, 6345073.1, 196713, 3453252.55, 0860990, 2534766, 98677462.3, 82345696.35, 5471874.65, 
  76455685.8,78755124.1, 5239125, 74619833.87, 59872465.65, 56545067.35, 5432387.9, 754611848.8, 
  7645287, 6566209.4), noClaims = c(1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 4L, 
  3L, 3L, 1L, 4L, 8L, 4L, 4L, 1L, 2L, 1L, 1L), fromdate = structure(c(16252, 
  16252, 16252, 16252, 16252, 16252, 16252, 16922, 16071, 16071, 
  16436, 16436, 16801, 16191, 16102, 16071, 17532, 17532, 17532, 
  17532), class = "Date")), class = c("data.table", "data.frame"
  ), row.names = c(NA, -20L),
  </code></pre>