Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206553

How do I make a nested for loop in R that multiples X & X?

$
0
0

So I'm trying to do a nested for loop that will multiple 1:100 with 1:100 (10,000 possible combinations). So 1*1, 1*2 ... 1* 100. Once it reaches 100, I want it to repeat, so 2*1, 2*2, 2*100.

Of note: I need to be doing this using for loops

table<-matrix(ncol=3, nrow=100*100)
for (i in 1:100) {
  for (z in 1:100){
    answer<-i*z
    table[i,] <- c(i,z,answer)
  }
}

Here's my code above. It seems like an easy fix, but I'm missing something..


Viewing all articles
Browse latest Browse all 206553

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>