R- sqldf error raw vs double

后端 未结 1 1835
生来不讨喜
生来不讨喜 2021-01-25 09:51

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
         


        
1条回答
  •  遥遥无期
    2021-01-25 10:27

    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.

    0 讨论(0)
提交回复
热议问题