I want to simplify some code that I am running. I am trying to pull the dimensions of multiple datasets that result from SQL queries. I want to try to loop through the dataset names
I have been able to get my desired result, I'm just not sure it's the most efficient way of going about this: I have a separate SQL query line for each dataset.
This is the original code:
library(sqldf)
dim(sqldf("select Group1, count(*) as Count from Data1 group by Group1"))[1]
dim(sqldf("select Group1, count(*) as Count from Data2 group by Group1"))[1]
dim(sqldf("select Group1, count(*) as Count from DataN group by Group1"))[1]
This is my attempt at simplifying the code:
datalist=c(Data1,Data2,...DataN)
abc=vector("list",length(datalist))
for (i in seq_along(datalist))
abc[[i]]=dim(sqldf("select Group1, count(*) as Count from datalist[i] group by Group1"))[1]
I expect the output to show N numbers for each dataset but I get an error message that reads "no such table: datalist."