编辑-1
我的实际数据库是 MSAccess 格式,我正在使用R 包中的sqlQuery
函数导入数据RODBC
。以下是我正在创建的假数据库,以便我可以使用RSQLite
包提供可重现的示例。我想在函数中使用正则表达式
sqlQuery
。
EDIT-1结束
以下是使用RSQLite
包的模拟数据库和关联查询。(REGEX
或REGEXP
)函数不起作用,我不知道为什么。
data0 <- read.csv(textConnection(
'ID value
P9W38 97
P9W39 17
P9W40 78
P9W41 7
P9W42_1 38
P9W42 13
P9W43 18
P9W44 76
P9W45 65
P9W46 24
P9W46_1 44
P9W47 8
P9W48 31
P9W49 82
P9W50 52
P9W50_2 55
P9W51 26
P9W52 33
P9W52_2 79
P9W53 67
P9W54 74
P9W55 55'
),sep='')
dbWriteTable(con, "Mydata", data0)
这些工作
dbGetQuery(con, paste0(' select * from Mydata where [ID] like \'P9W38\' '))
dbGetQuery(con, paste0(' select * from Mydata where [ID] like \'P9W42%\' '))
但是这些不起作用
dbGetQuery(con, paste0(' select * from Mydata where [ID] REGEX \'P9W(38|40|50)\' '))
dbGetQuery(con, paste0(' select * from Mydata where [ID] REGEX \'P9W(38|40|50)(_1){,1}\' '))
有什么建议吗?