0

I am trying to get the row counts of all my tables with a query and I want to save the results in a dataframe. Right now, it only saves one value and I'm not sure what the issue is. Thanks for any help.

schema <- "test"
table_prefix <- "results_"
row_count <- list()
for (geo in geos){
  table_name <- paste0(schema, ".", table_prefix, geo)
  queries <-   paste("SELECT COUNT(*) FROM", table_name)
}

for (x in queries){
  row_count <- dbGetQuery(con, x)
}
mjoy
  • 606
  • 2
  • 9
  • 19
  • 4
    You need to index the output object by `[geo]` (in the first loop) and `[x]` in the second loop, otherwise you overwrite the output object on each loop iteration. – Thomas Aug 17 '18 at 17:55
  • for some reason when I tried that before I was getting errors but now it worked so thanks – mjoy Aug 17 '18 at 17:58
  • 1
    Glad the problem was solved! Feel free to write out what worked as your own answer and accept it – divibisan Aug 17 '18 at 18:02
  • 1
    [Can I answer my own question?](https://stackoverflow.com/help/self-answer) – AkselA Aug 17 '18 at 18:06

0 Answers0