在glm中用for循环使用paste() [英] using paste() in a for loop with glm
问题描述
SPCA2 = df.pts [,3]
CLQU2 = df。 pts [,4]
df.list = list(SPCA2,CLQU2)
for(i in df.list){
qp.mod = glm(粘贴(i,〜NDVI + ELEV),family =quasipoisson,data = my.data)
print(summary(gp.mod))
}
非常感谢!主要的问题是,df.list是一个向量列表,应该是一个名称列表。
换句话说,要纠正这个问题...
pre $ $ $ $ $ $ df.list =(SPCA2,CLQU2)
而不是
df.list = list(SPCA2,CLQU2)
然而,正确地指出数据帧my.data不是正确的数据框。最后,虽然没有它,但函数as.formula()也起作用。再次,非常感谢!
In the code below, df.pts is a dataframe. I'd like to run about dozen glm models using different y variable (only two shown in the code). I'm using a for loop with the paste() function, but I can't seem to get the paste() function to work properly. What am I missing with paste()?
SPCA2 = df.pts[,3]
CLQU2 = df.pts[,4]
df.list = list(SPCA2, CLQU2)
for (i in df.list) {
qp.mod = glm(paste(i,"~NDVI+ELEV"), family="quasipoisson", data=my.data)
print(summary(gp.mod))
}
Many thanks! The main problem was that df.list was a list of vectors, and should have been a list of names.
I other words, to correct the problem...
df.list = ("SPCA2", "CLQU2")
instead of
df.list = list(SPCA2, CLQU2)
However, it was also correctly pointed out that the dataframe, my.data, was not the correct dataframe. Finally, while it worked without it, the function as.formula() also worked. Again, many thanks!
这篇关于在glm中用for循环使用paste()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!