我有以下mySQL查询:
sqldf( "select * from data WHERE TEXT RLIKE '[[:<:]]digital[[:>:]]' OR TEXT RLIKE '[[:<:]]data[[:>:]]' OR TEXT RLIKE '[[:<:]]agile[[:>:]]' OR (TEXT RLIKE '[[:<:]]self[[:>:]]' AND TEXT RLIKE '[[:<:]]service[[:>:]]') OR TEXT RLIKE '[[:<:]]cloud[[:>:]]' OR TEXT RLIKE '[[:<:]]insight[^[:space:]]+[[:>:]]' OR TEXT RLIKE '[[:<:]]modern[^[:space:]]+[[:>:]]'")
我想使用sqldf包在R中应用它:
data <- structure(list(Participant = 1:3, A = c("and other agile digital, things", "testing test and modern", "nothing here"), B = c("", "b", "b"), C = c("c", "c", "c")), .Names = c("Participant", "TEXT", "other", "another"), row.names = c(NA, -3L), class = "data.frame")
我想针对一些示例数据运行:
Error in sqliteSendQuery(con, statement, bind.data) : error in statement: near "RLIKE": syntax error
我收到以下错误
int getNeighborhood(const char** grid, int N, int row, int col, int& bCount, int& fCount, int& rCount, int& gCount){
int currRow;
int currCol;
int countB = 0;
int countF = 0;
int countR = 0;
int countG = 0;
//loop through all 8 grids surrounding the current row and column.
for(int i = -1; i < 2; i++)
{
for(int j = -1; j < 2; j++){
currRow = row + i; //current row.
currCol = col + i; //current column.
if(currRow >= 0 && currRow < N && currCol >= 0 && currCol < N){
if(grid[row][col] == 'B')
{
++countB;
}
if(grid[row][col] == 'F')
{
++countF;
}
if(grid[row][col] == 'R')
{
++countR;
}
if(grid[row][col] == 'G')
{
++countG;
}
}
}
//return statement required
}
看起来这个包不喜欢RLIKE语句。为什么,以及如何解决这个问题?
答案 0 :(得分:2)
包含所需结果总是好的。基于this source,您似乎想要提取TEXT
- 列foo
后面跟有非空格字符的行。
你也可以在R grep
- 函数:
dat[grep('.*(foo)[^ ]', dat$TEXT),]
给出:
Participant TEXT other another
1 1 and other foo, things c
PS:最好不要为数据集指定与函数相同的名称;出于这个原因,我使用了dat
而不是data