mercredi 8 février 2017

R: Selecting a subset of a sqlite database based on a character vector

Vote count: 0

I am trying to extract part of my database using a character vector. To explain, I have used the mtcars data as below:

library(dplyr)
library(sqldf)

df <- cbind(rownames(mtcars),mtcars)
colnames(df)[1] <- "CarName"
CarsToFind <- c("Valiant", "Merc 280", "Lotus Europa", "Volvo 142E")

I could find the section of the data frame that I am interested in using:

mini_df <- df[df$CarName %in% CarsToFind,]

but my real data is quite large and I would rather not extract the whole thing into a data frame. I am looking for something similar to :

sqldf("SELECT * FROM mtcars WHERE CarName IN CarsToFind")

but this gives me the error: "no such table: CarsToFind". I don't want to create the table 'CarsToFind' in the sql databank, because I have many different querries that I want to perform on a once off basis. Is it possible to querry the sql using such a character vector?

asked 16 secs ago

Let's block ads! (Why?)



R: Selecting a subset of a sqlite database based on a character vector

Aucun commentaire:

Enregistrer un commentaire