3

Is there a different function in R to use to get the same result as in SQL for left or right function?

For instance, the following query in SQL would give the first 6 characters of a column:

select left(x, 6)
from table

However, when I try this in sqldf like this:

sqldf("select left(x,6) from table")

I get the following error:

Error in sqliteSendQuery(con, statement, bind.data) :

error in statement: near "(": syntax error

It gives me the x variable but not left(x,6). To clarify, the length of x is more than 6.

Community
  • 1
  • 1
asiehh
  • 553
  • 12
  • 22

1 Answers1

8

In sqldf, the function is named leftstr, not left. (answer by G.Grothendieck in the comment)

scoa
  • 19,359
  • 5
  • 65
  • 80
asiehh
  • 553
  • 12
  • 22
  • Note that you can find `leftstr` and the other additional SQLite functions that are available here: `library(RSQLite); help("initExtension")` . – G. Grothendieck Jul 20 '16 at 10:56