I'm trying to import a file back into r which contains four different tables. I basically carried out this solution to a previous question and managed to get the connection established. However, I just want to use one of the tables from the sql file instead of loading all tables from my sql into R, so I performed the following:-
library(DBI)
library(SQLite)
con <- dbConnect(RSQLite::SQLite(), dbname = "diffs.sqlite")
tables <- dbListTables(con)
mzDiff <- dbGetQuery(conn = con, statement = paste("SELECT * FROM mzdiff", sep = ",")
However, I get this error message:-
Error in .Call(rsqlite_query_fetch, res@Id, nrec = as.integer(n)) :
negative length vectors are not allowed
which I don't get given that the data contained within the mzdiff table was originally exported from R into sqlite, and so there shouldn't be a memory issue, but by the looks of it that's what I'm currently having issues with when trying to get the data back from sql into R. Any ideas of what I can do/if I'm doing something wrong?
Alternatively I can do what I need to do in sqlite, but I'm not familiar with it. I was going to bin my data in R by doing (mzdiff replaced by data):-
bin <- seq(min(data[, 1]), max(data[, 1]), by = 0.001)
binnedData <- tapply(data[, 1], cut(data[, 1], breaks = bin), median)
Is it possible to bin data in SQL similarly to how I want to do so in R?
Thanks