用于R中的双循环

时间:2012-08-20 08:13:44

标签: r loops

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

生成:

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

如下所示:

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

1 个答案:

答案 0 :(得分:3)

你真的不需要for循环:

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

给出:

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

如果您想以特定方式打印它,您可以循环显示此结果并打印。