You are creating n*m=1000 times a vector with n=10 elements (it should be a vector with m=100 elements) but your programs only return the last one created. That quite inefficient 😉
I am trying to generate n samples of size m from the uniform (0,1). I am using runif(1,0,1) in the loop. Please see the attached file. Thanks
So I interpret what yo write that way that at the end you would like a nested n x 1 vector where each element is a m x 1 vector of random numbers.
So must note that "runif" always creates a matrix/vector. The command runif(1,0,1) creates a 1 x 1 matrix, wbich is probably not what you want.
Your program actually creates the n * m random values, but every new run in the k-loop overwrites the values created in the i-loop before. Furthermore a program (unless you explicitly use the "return" statement) always returns the last value it calculated and in our case thats the last value b[m in the last run of your loops and thats the reason you juts get one single 1x1 matrix with just one number as your output.
If you really want to calculate each of the n*m values singly you should use the "rnd" conmmand and not "runif". The most "logical" way to do it with two nested loops would be this
but Prime refuses the usage of the double vector indices when creating b[i]k. So we have to resort to using am temporary variable
BUT ....
as you already know about the runif command and its ability to create a vector, why not use it to create each m x 1 vector in one go and just use the k-loop to create n of these vectors:
I would prefer this way (using a loop), but you could also use a range variable to do the job instead of a for-loop
Thank you for the prompt solution, Werner. Highly appreciated. However, the first suggestion does not work. Please see the attached code. It gives an error saying the tmp variable is not defined.