Using R, I want to create 10 vectors (say 10x1) and concatenate their results into a matrix (say 10x10) one at a time.
I figured that it might be most computationally-efficient to initialize an empty matrix first and then replace its values, column by column, with the vectors of interest.
This is what I tried.
# Initialize empty matrix
empty.m = matrix(nrow = 10, ncol = 10)
#Create vectors and attempt to insert them into matrix
for (i in 1:10) {
empty.m[, i] = sample(10)
}
My attempt to insert the output of sample into the matrix empty.m does not work, yielding the following error:
Error in matrix[, 1] = vec : object of type 'closure' is not subsettable
Do you have any suggestions for what I can do to accomplish what I want, avoiding this error?