Search code examples
rjoinmergesqldfrsqlite

sqldf in R generating an Error


I am trying to merge two tables in R by using the following command:

library(gsubfn)
library(proto)
library(RSQLite)
library(sqldf)
sqldf("SELECT Gender, Pmu.try.Sat.Ltd, Online.Campus.Student, Residency,
           tutorial_avg_score
           FROM A JOIN B
           USING(userID)")

The system generates the following error:

Error in result_create(conn@ptr, statement) : near ".": syntax error

Could anyone kindly advise what could be the issue here? The column names are bit weird but they are very similar to the actual names that I have in the provided data. I had a look at the following question: Error in rsqlite_send_query(conn@ptr, statement) : near "(": syntax error But it does not help me either.

Looking for your kind advice on this!


Solution

  • The following solutions resolved the error that I had been facing:

    sqldf('SELECT Gender, "Pmu.try.Sat.Ltd", "Online.Campus.Student", Residency,
           tutorial_avg_score
           FROM A JOIN B
           USING(userID)')
    

    OR

    sqldf('SELECT Gender, `Pmu.try.Sat.Ltd`, `Online.Campus.Student`, Residency,
           tutorial_avg_score
           FROM A JOIN B
           USING(userID)')
    

    OR

    sqldf('SELECT Gender, [Pmu.try.Sat.Ltd], [Online.Campus.Student], Residency,
           tutorial_avg_score
           FROM A JOIN B
           USING(userID)')
    

    Many thanks @G. Grothendieck for your kind comments!