各位大佬,想请教一下怎么在for循环语句中,把2个变量传递到sqldf语句中
目前我写的循环如下:
for (i in 1:16) {
for (j in 1:4){
for (k in 1:4){
tmp1 = paste0("R",j)
tmp2 = paste0("M",j)
Data[] <- sqldf(sprintf('select * from 原始数据 where 特征1 is "%s" and 特征2 is "%s"', tmp1, tmp2))
}
}
}
数据大概长这样:
账号 特征1 特征2
aa001 R1 M1
aa002 R2 M2
aa003 R3 M2
aa004 R1 M2
aa003 R3 M4
aa004 R1 M4
我尝试了一下,如果利用%s只传递1个变量是可以做的正确识别的,但两个就不行,不知道是不是格式不对
目标就是可以让sqldf 循环出来
Data[] <- sqldf('select * from 原始数据 where 特征1 is "R1到R4" and 特征2 is "M1到M4"')
感谢各位大佬