运行 用于比较整数的 sqldf 命令中的问题

Issue in running sqldf command for comparing integers

我正在处理如下简单数据:

teacher student
  12      409
  43      403
  12      415
  12      409
  67      311
  19      201

我正在尝试检索 teacher = 12student = 409 的条目。我正在使用以下命令:

library(sqldf)
sqldf('SELECT * 
      FROM df
      WHERE teacher == 12 and student == 409')

我知道这是一个基本命令,但是当我 运行 它时,我收到以下错误消息:

Error in asfn(rs[[i]]) : need explicit units for numeric conversion

我得到同样的错误,即使我 运行:

# Without the and condition
sqldf('SELECT * 
      FROM df
      WHERE teacher == 12')

或者当我运行这个

# Single equal sign
sqldf('SELECT * 
      FROM df
      WHERE teacher = 12')

请注意,在我当前的数据集中,df$teacherdf$student 都是整数。我想了解为什么会出现此错误。任何建议将不胜感激。

我想要的输出是:

teacher   student
  12        409
  12        409

谢谢!

我们只需要一个人=

library(sqldf)
sqldf('SELECT * 
      FROM df
      WHERE teacher = 12 and student = 409')

-输出

 teacher student
1      12     409
2      12     409

使用 OP 的原始数据,这并没有解决,所以,我们可以使用 method 参数`

sqldf('SELECT * 
      FROM df
      WHERE teacher = 12 and student = 409', method = 'name__class')

根据?sqldf"name__class"Date class作为例子。由于OP的原始数据没有共享,所以仍然不确定为什么会起作用

method = "name__class" which means that columns names that end in __class with two underscores where class is an R class (such as Date) are converted to that class and the __class portion is removed from the column name.`

数据

df <- structure(list(teacher = c(12L, 43L, 12L, 12L, 67L, 19L), student = c(409L, 
403L, 415L, 409L, 311L, 201L)), class = "data.frame", row.names = c(NA, 
-6L))