RMySQL和data.frame:强制将NA引入整数范围

时间:2018-10-19 02:09:00

标签: mysql r rmysql

我正在从MySQL数据库中提取数据。数据在MySQL中具有浮点结构,但是将它们加载到数据帧中时出现以下错误:“ NA强制转换为整数范围的NA”

这是MySQL函数:

##
## MySQL function
##
library(RMySQL)
rozDB <- function(q,type) {
  mysql_conn <- dbConnect(
    MySQL(), 
    user="", 
    password="", 
    dbname="", 
    host="")

  if(type == "select") {
    query <- dbSendQuery(mysql_conn, q)
    result <- fetch(query, n = Inf)
    check <- dbHasCompleted(query)
  }

  if(type == "insert") {
    query <- dbSendQuery(mysql_conn, q)
    result <- "Complete"
  }

  dbClearResult(query)
  dbDisconnect(mysql_conn)

  return(result)
}

和数据调用:

###
### Build condition map and number of sessions
###

conditions <- c()
query1 <- paste0("SELECT notebook_condition conditions, COUNT(notebook_condition) count FROM key_map GROUP BY notebook_condition;")
conditions <- rozDB(query1, "select")


### 
### Get 1 day of 1 condition
###

selectedCondition <- conditions[3,]

for(i in 1:selectedCondition[1,2]){
  query3 <- paste0("SELECT kx,ky,kz FROM dataread3 WHERE `datetime` BETWEEN (SELECT `start_time` FROM key_map WHERE `cond` = '",selectedCondition[1,1],"' LIMIT ",i,",1) AND (SELECT `end_time` FROM key_map WHERE `cond` = '",selectedCondition[1,1],"' LIMIT ",i,",1);")
  print(query3)
  data <- rozDB(query3,"select")
}

0 个答案:

没有答案