Select 列值部分匹配的数据框中的行
Select rows in data frame with partial match in values of column
假设我有以下数据集
d <- data.frame(1:31, 31:1)
names(d) <- c("1st", "2nd")
我想 select 在名为“1st”的列中出现“3”的列(即第 3、13 和 31 列应该 selected,但不是第 1 列, 9 和 29).
sqldf("select * from d where 1st LIKE '%3%'")
给我错误:
Error: unrecognized token: "1st"
如何select基于部分匹配对数据框的一部分进行子集化?
期望的输出:
1st 2nd
3 29
13 19
31 1
非常感谢任何帮助
我们有非法列名称,将其括在方括号中:
sqldf("select * from d where [1st] LIKE '%3%'")
# 1st 2nd
# 1 3 29
# 2 13 19
# 3 23 9
# 4 30 2
# 5 31 1
关于非法:
- What are valid table names in SQLite?
I haven't found a reference for it, but table names that are valid without using brackets around them should be any alphanumeric combination that doesn't start with a digit
假设我有以下数据集
d <- data.frame(1:31, 31:1)
names(d) <- c("1st", "2nd")
我想 select 在名为“1st”的列中出现“3”的列(即第 3、13 和 31 列应该 selected,但不是第 1 列, 9 和 29).
sqldf("select * from d where 1st LIKE '%3%'")
给我错误:
Error: unrecognized token: "1st"
如何select基于部分匹配对数据框的一部分进行子集化?
期望的输出:
1st 2nd
3 29
13 19
31 1
非常感谢任何帮助
我们有非法列名称,将其括在方括号中:
sqldf("select * from d where [1st] LIKE '%3%'")
# 1st 2nd
# 1 3 29
# 2 13 19
# 3 23 9
# 4 30 2
# 5 31 1
关于非法:
- What are valid table names in SQLite?
I haven't found a reference for it, but table names that are valid without using brackets around them should be any alphanumeric combination that doesn't start with a digit