问题描述
我有一个向量 lims,有分数的限制:
[1] 0.000000 7.025894 9.871630 12.411131 15.155998 18.099176 21.431354 25.391163 30.6165550 6 3
我创建了一个表格来对其他客户进行分类:
lims[1]
所以我的结果是:
>利姆斯最小Sc 最大Sc1 -0.000010 7.0258942 7.025894 9.8716303 9.871630 12.4111314 12.411131 15.1559985 15.155998 18.0991766 18.099176 21.4313547 21.431354 25.3911638 25.391163 30.6165509 30.616550 40.35663010 40.356630 100.000000
我想根据这些限制和字段 sc 对另一个表(火车)进行分类:
>class(train$sc)[1]数字">班级(火车$目标)[1] 整数"
但是当我运行以下命令时,出现错误:
库(sqldf)sqldf("选择b.minSc, b.maxSc, count(*) 作为total, sum(target) as compra从火车 a 左加入 lims b在 a.scb.minSc分组 b.minSc, b.maxSc")
sqliteSendQuery(conn, statement, bind.data) 中的错误:RAW() 可以仅适用于原始",而不适用于双重"
我不明白我做错了什么.
我相信错误在于您的 lims
对象.
lims
注意 lims$maxSc
是 data.frame
类型.然后以下查询不起作用并导致您发布的错误.
库(sqldf)sqldf("从 lims 中选择 *")
但是,如果将 lims$maxSc
设置为 a[,1]
则没有错误.
lims$maxSc
data.frame
的列不能是 data.frame
类,以便 sqldf
可以工作.
I have a vector lims, with the limits of a score:
[1] 0.000000 7.025894 9.871630 12.411131 15.155998 18.099176 21.431354 25.391163 30.616550 40.356630
I create a table to classify other clients with:
lims[1]<- -0.00001
a<-data.frame(lims[2:10])
colnames(a)<-'maxSc'
a<-rbind(a, 100)
lims<-data.frame(lims)
lims$maxSc<-a
colnames(lims)<-c('minSc', 'maxSc')
> class(lims)
[1] "data.frame"
So my result is:
> lims
minSc maxSc
1 -0.000010 7.025894
2 7.025894 9.871630
3 9.871630 12.411131
4 12.411131 15.155998
5 15.155998 18.099176
6 18.099176 21.431354
7 21.431354 25.391163
8 25.391163 30.616550
9 30.616550 40.356630
10 40.356630 100.000000
I want to classify another table (train) according to those limits and the field sc:
>class(train$sc)
[1] "numeric"
> class(train$target)
[1] "integer"
But when I run the following I get an error:
library(sqldf)
sqldf("Select b.minSc, b.maxSc, count(*) as total, sum(target) as compra
from train a left join lims b
on a.sc<=b.maxSc and a.sc>b.minSc
group by b.minSc, b.maxSc")
I don't understand what I'm doing wrong.
I believe the error lies in your lims
object.
lims <- c(0.000000, 7.025894, 9.871630, 12.411131,
15.155998, 18.099176, 21.431354, 25.391163,
30.616550, 40.356630)
lims[1]<- -0.00001
a<-data.frame(lims[2:10])
colnames(a)<-'maxSc'
a<-rbind(a, 100)
lims<-data.frame(lims)
lims$maxSc<-a
colnames(lims)<-c('minSc', 'maxSc')
sapply(lims, class)
# minSc maxSc
# "numeric" "data.frame"
Notice that lims$maxSc
is of type data.frame
. Then the following query doesn't work and results in the error you posted.
library(sqldf)
sqldf("select * from lims")
However, if instead lims$maxSc
is set to a[,1]
then there is no error.
lims$maxSc<-a[,1]
sapply(lims,class)
# minSc maxSc
# "numeric" "numeric"
sqldf("select * from lims")
The columns of your data.frame
cannot be of class data.frame
for sqldf
to work.
这篇关于R- sqldf 错误原始与双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!