implement a two nested loop in R
Code snippet on how to implement a two nested loop in R
for (i in 1:10){
for (j in 1:10){
print(paste(i, j, sep = "+"))
}
}
This code implements two nested loops in R. The outer loop is controlled by variable i, which iterates in the sequence 1-10. The inner loop is controlled by variable j and it also iterates in the sequence 1-10. For each value of i, the inner loop is executed 10 times, and it prints out a string consisting of the value of i and j combined using the ‘+’ as a separator. So, the output will contain all combinations of i and j, i.e. (1+1, 1+2, 1+3 and so on up to 10+10).