问题
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.
回答1:
In sqldf
, the function is named leftstr
, not left
. (answer by G.Grothendieck in the comment)
来源:https://stackoverflow.com/questions/31843373/how-to-use-right-left-to-split-a-variable-in-sqldf-as-in-leftx-n