问题
I am using sqldf package and sql analyze one table generated by a classification model.
But when I use the code:
table<-sqldf("
SELECT a,
b,
c,
d,
e,
f,
CASE WHEN (REGEXP_LIKE(t, '\b(2nd time|3rd time|4th time)\b')) = TRUE
THEN 1 ELSE 0 END AS UPSET_NOT_LIKE,
regexp_extract(t, '\b(2nd time|3rd time|4th time)\b')) as Word
FROM cls
")
It looks like that the sqldf package don't have regexp_like and regexp_extract function.
Is there any sql-advanced packages that I can use to do the query?
回答1:
sqldf works with SQLite, h2, mysql and postgresql backends.
The default is SQLite and it does not support those functions. SQLite does support the regexp keyword if SQLite was compiled with support but I don't think the driver in the RSQLite package has done so.
If you use the postgreSQL database backend to sqldf
then the ~
operator is available to do regexp matching and regexp_matches
is available to extract matches.
See FAQ#12 on the sqldf home page for info on using the postgreSQL backend with sqldf.
See here for info on regular expression matching in postgreSQL.
In the future please provide complete minimal self contained reproducible examples in your questions which in this case means also providing a sample of the rows of cls
, e.g. dput(head(cls))
.
来源:https://stackoverflow.com/questions/33026213/regarding-sqldf-package-regexp-function