hollo056
hollo056

Reputation: 31

Can't figure out why syntax error near "from" is appearing for sqldf in R

I'm trying to compare subject IDs between columns to find unique IDs. I keep on getting a syntax error even though I've spent the past hour checking and re-checking my syntax. I decided to make a simple data frame to play around with an low and behold I get the same error.

Here my syntax for the proxy data frame

color <- c('yellow', 'red', 'green', 'blue') 
number <- c(1,3,4,5) 
stuff <- data.frame(color, number) 

sqldf('select number, from stuff where color = red')

Here's the error I got

Error in sqliteSendQuery(con, statement, bind.data) : error in statement: near "from": syntax error

I'm beyond frustrated that I can't get this simple query to work. What gives? I even tried removing the comma before 'from' and then I get the following error.

Error in sqliteSendQuery(con, statement, bind.data) : error in statement: no such column: red

Upvotes: 1

Views: 6325

Answers (1)

fishtank
fishtank

Reputation: 3728

Remove commas and change quotes:

> stuff
   color number
1 yellow      1
2    red      3
3  green      4
4   blue      5

> sqldf("select number from stuff where color = 'red'")
  number
1      3

Upvotes: 3

Related Questions