问题
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")
Error in sqliteSendQuery(conn, statement, bind.data) : RAW() can only be applied to a 'raw', not a 'double'
I don't understand what I'm doing wrong.
回答1:
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.
来源:https://stackoverflow.com/questions/33676537/r-sqldf-error-raw-vs-double