将for循环的结果存储在唯一对象中 [英] store results of for loop in unique objects
问题描述
mdl< b
-i
}
如何获得30 mdl
而不是只有一个
, mdl
(这是因为在循环中 mdli
mdli + 1
在我每次迭代的时候,我想要的都是30 mdl
> mdl1 mdl2
.... mdl30
我试过这个:
pre $ for(i in seq(1,30)){
mdli <-i
>
但是如果我输入 mdl1
,它表示 mdl1找不到
,而输入 mdli
则给出了<$ c
谢谢
你可以指定你的store变量,而不必确定它应该存储多少个值,如果你想为每个值分开一个变量,看看粘贴
函数。
x < - NULL
for(i in 1:10){
x [i]< - 我* 2
}
*编辑:上面的评论是正确的。这种方式不是最有效的。但是当计算时间不是问题时我仍然使用它。
Here is a simple loop
for (i in seq(1,30)) {
mdl<-i
}
How do I get 30 mdl
rather than just one mdl
(which is happening because within the loop, mdli
is being replaced by mdli+1
at every iteration. What I want is to have 30 mdl
perhaps with names like mdl1
, mdl2
....mdl30
I tried this:
for (i in seq(1,30)) {
mdli<-i
}
But if I type mdl1
, it says mdl1 not found
whereas typing mdli
gives me the value of i=5
Thank you
You can specify your store variable beforhand without determine how many values it shall store. If you want for each value a seperate variable take a look at the paste
function.
x<- NULL
for (i in 1:10){
x[i] <- i*2
}
*edit: The comment above is right. This way is not the most efficent one. But I still use it when computation time is not an issue.
这篇关于将for循环的结果存储在唯一对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!