I have data frame of SQL queries I would like to execute on another data frame.
queries <- structure(list(Name = c("innovation", "foos", "testing"), A = c("select * from data WHERE `TEXT` RLIKE '[[:<:]]innovat[^[:space:]]+[[:>:]]'", "select * from data WHERE `TEXT` RLIKE '[[:<:]]foo[^[:space:]]+[[:>:]]'", "select * from data WHERE `TEXT` RLIKE '[[:<:]]test[^[:space:]]+[[:>:]]'"), B = c("", "b", "b"), C = c("c", "c", "c")), .Names = c("Name", "Query", "Q1_2", "Q1_3"), row.names = c(NA, -3L), class = "data.frame")
I would like to loop through these queries using the package sqldf, and name the data frame output from each query its correspond name found in the data frame queries. I also need to create a new variable in each dataframe that matches the data frame name.
Sample dataset
data <- structure(list(Participant = 1:3, A = c("and other foo things", "testing test and foo", "nothing here"), B = c("", "b", "b"), C = c("c", "c", "c")), .Names = c("Participant", "TEXT", "other", "another"), row.names = c(NA, -3L), class = "data.frame")
Something like:
for (i in queries[2]) {
i<- as.data.frame(sqldf(i)
i$category <- i
}
But this doesn't work yet. Suggestions?