简体   繁体   English

用于R中的双循环

[英]for double loop in R

for(i in 0:3) {
    for (j in quantile(0:80,probs=c(0,0.33,0.67,1))) {
        print(paste(i,j,sep=","))
    }
}

Generate: 生成:

"0,0"  
"0,26.4"  
"0,53.6"  
"0,80"  
"1,0"  
"1,26.4"  
.  
.  
.  

What about generating like below: 如何生成如下所示:

"0,0"  
"1,26.4"  
"2,53.6"  
"3,80"  
?  

you don't really need a for loop for that: 您实际上并不需要for循环:

paste(0:3,quantile(0:80,probs=c(0,0.33,0.67,1)),sep=",")

gives: 给出:

[1] "0,0"    "1,26.4" "2,53.6" "3,80"  

If you want to print it in that specific way you could just loop over this result and print. 如果要以特定方式打印它,则可以遍历此结果并打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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