title: R sqldf "error in statement: near "–": syntax error"
body: <p>I have the following dataset that I am using to calculate re-hospitalization within 30 days from, using SQL code within R. </p>
  
  <pre><code>  str(tb1)
  
  Classes ‘data.table’ and 'data.frame':  35255 obs. of  56 variables:
   $ Source                   : Factor w/ 2 levels "C","E": 1 1 1 1 1 1    1     1 1 2 ...
   $ UniversalID              : int  712 123 123 123 156 189 481 ...
   $ DOB                      : Factor w/ 5491 levels "1/1/1997","1/1/1998",..: 2431 2431 2431 2431 2431 2431 2431 2431 2431 459 ...
  $ Gender                   : Factor w/ 2 levels "FEMALE","MALE": 1 1 1 1 1 1 1 1 1 1 ...
  $ AgeonDOS                 : int  14 14 14 14 14 14 14 14 14 17 ...
  $ RaceDescription          : Factor w/ 7 levels "Asian or Pacific Islander",..: 7 7 7 7 7 7 7 7 7 7 ...
  $ ClaimType                : Factor w/ 5 levels "C","H","I","L",..: 3 3 3 3 3 3 3 3 3 3 ...
  $ ClaimTypeDescription     : Factor w/ 5 levels "Home Health Claims",..: 2 2 2 2 2 2 2 2 2 2 ...
  $ CYTDOS                   : int  2014 2014 2014 2014 2014 2014 2014 2014 2014 2014 ...
  $ FDOS                     : Factor w/ 385 levels "1/1/2014","1/10/2014",..: 350 350 350 350 350 350 350 350 350 353 ...
  $ TDOS                     : Factor w/ 365 levels "1/1/2014","1/10/2014",..: 306 306 306 306 306 306 306 306 306 309 ...
  </code></pre>
  
  <p>When I run my sqldf I get the following error:</p>
  
  <pre><code>&gt; readcount&lt;-sqldf("SELECT A.UniversalID , A.TDOS, B.FDOS, A.PROC,A.seqno
  +                   FROM tb1 AS A
  +                  JOIN tb1 AS B 
  +                 ON A.UniversalID = B.UniversalID
  +                where  B.seqno = A.seqno + 1 and B.FDOS – A.TDOS between 0 and 30
  +              ")
  Error in sqliteSendQuery(con, statement, bind.data) : 
    error in statement: near "–": syntax error
  </code></pre>
  
  <p>Which I don't get if I don't include the last where clause:</p>
  
  <pre><code>&gt; readcount&lt;-sqldf("SELECT A.UniversalID , A.TDOS, B.FDOS, A.PROC,A.seqno
  +                  FROM tb1 AS A
  +                  JOIN tb1 AS B 
  +                  ON A.UniversalID = B.UniversalID
  +                   where B.seqno = A.seqno + 1
  +                  ")
  &gt; 
  </code></pre>
  
  <p>What's wrong with B.FDOS-A.TDOS between 0 and 30 ?</p>
  
  <p>I also tried the following:</p>
  
  <pre><code>    &gt; readcount&lt;-sqldf("SELECT A.UniversalID , A.TDOS, B.FDOS, A.PROC,A.seqno
     +                   FROM tb1 AS A
     +                  JOIN tb1 AS B 
     +                 ON A.UniversalID = B.UniversalID
     +                where  B.seqno = A.seqno + 1 and DATEDIFF(A.TDOS,B.FDOS) between 0 and 30 
     +              ")
     Error in sqliteSendQuery(con, statement, bind.data) : 
    error in statement: no such function: DATEDIFF
  </code></pre>