简体   繁体   中英

Selecting one item in a list at a time

Is there a way to select one item in a list at a time? I've attempted this with the get() function, but I did not have any luck. I have 3537 character items in a list. I would like to select one character item at a time, run a set of code on using that item, then move on to another in a for loop. What might be an efficient way to accomplish this?

l <- dbListTables(mydb)

random_tables <- sample(3537, 300, replace = TRUE)
plot_list <- vector('list', 300)

for (i in seq_along(random_tables)){
# Reads the selected table in database
ind <- dbReadTable(mydb, get(l))
# Other code...
...
}

If l are the name of the tables, you can do:

l <- dbListTables(mydb)

random_tables <- sample(l, 300)
plot_list <- vector('list', 300)

for (i in seq_along(random_tables)){
  # Reads the selected table in database
  ind <- dbReadTable(mydb, random_tables[i])
  # Other code...
  #...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM