Nellicopter
Nellicopter

Reputation: 83

"Error: near ".": syntax error" with sqldf in R

For whatever reasons, my code that used to work does not work anymore and I get the following error message "Error: near ".": syntax error". The code is below. How should I modify it to make it work again? Thank you very much!

uhc_phys <- sqldf("select 
      a.iso3,a.year,a.whoname,a.Phys
      b.iso3,b.year,b.whoname,b.Phys
      min(abs(a.year - b.year)) min_value
    from uhc_hwf a  
    left join uhc_hwf b on a.year - b.year in (0,1,2,3,4,5) and
      a.iso3 = b.iso3 and
      b.Phys is not null
    group by a.iso3, a.year
    having a.year in ('2012','2017')")[1:8]

Upvotes: 0

Views: 863

Answers (1)

r2evans
r2evans

Reputation: 160407

You are missing commas between some of your selected fields. Try this:

uhc_phys <- sqldf("select 
      a.iso3,a.year,a.whoname,a.Phys        ,
      b.iso3,b.year,b.whoname,b.Phys        ,
      min(abs(a.year - b.year)) min_value
    from uhc_hwf a  
    left join uhc_hwf b on a.year - b.year in (0,1,2,3,4,5) and
      a.iso3 = b.iso3 and
      b.Phys is not null
    group by a.iso3, a.year
    having a.year in ('2012','2017')")[1:8]

(Commas spaced out a bit to highlight which ones are missing.)

Upvotes: 1

Related Questions