【发布时间】:2018-05-09 11:53:30
【问题描述】:
我必须创建一个循环,但我不知道如何命令 R 我想做的事情。
for(i in 1:nrow(File1))
for(j in 1:ncol(File2)){
if [(x(i,1)==(cd(1,j)))] # Until here I think it is ok
THEN # I don't know what is the command for THEN in R
for (k in File3) #I have to take all the data appearing in File3
Output (k,1)= K # I don't know what is the command to order the output in R
Output (k,2)= cd(1,j)
Output (k,3)= x(i,2)
Output (k,4)= x(i,3)
Output (k,5)= x(i,4)
Output (k,6)= cd(1,j)
我必须如何完成循环?
先谢谢了,我有点困惑
【问题讨论】:
-
在 R 中,通常最好使用矢量化而不是 for 循环,尤其是在您需要开始嵌套循环时。这是一篇很好的文章:bookdown.org/rdpeng/rprogdatascience/vectorized-operations.html