从R中的mysql中选择数据(带有for循环(?)) [英] select data from mysql (with for loop(?)) in R
本文介绍了从R中的mysql中选择数据(带有for循环(?))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的是:
m1 <- dbGetQuery(mydb, "select out,in from table where value > 1")
m2 <- dbGetQuery(mydb, "select out,in from table where value > 1.1")
m3 <- dbGetQuery(mydb, "select out,in from table where value > 1.2")
m4 <- dbGetQuery(mydb, "select out,in from table where value > 1.3")
.
.
.
m101 <- dbGetQuery(mydb, "select out,in from table where value > 10")
然后
n1 <- degree(graph.data.frame(m))
n2 <- degree(graph.data.frame(m2)
.
.
.
我想用apply函数简化这些代码,但我不知道:^(
I would like to simplify these codes with apply function but I have no clue :^(
推荐答案
这是一个for
循环解决方案,可将结果保存在列表中:
Here is a for
loop solution that saves the results in a list:
# get list
myList <- list()
for(i in seq(1, 10, 0.1)) {
myList[[paste0("m",i)]]<- dbGetQuery(mydb,
paste("select out,in from table where value >", i))
}
然后可以从列表中调用对象:
You can then call the objects out of you list:
n1 <- degree(graph.data.frame(myList[["m1"]]))
和上面一样,您可以将这些结果放在列表中.命名列表是存储和组织许多对象的好方法.
and as above, you can put these results in a list. Named lists are a great way to store and organize many objects.
这篇关于从R中的mysql中选择数据(带有for循环(?))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文