Home Getting an Error when trying to output every combination of values in a matrix using R
 I'm trying to replace the values in a data frame with every combination of values and then outputting them in a matrix. However, I get an error then I run it. Below is the code and a sample data. test_data=array(0,c(14^4,5,1)) for (a in seq(14)){ for (b in seq(14)){ for (c in seq(14)){ for (d in seq(14)){ if(a+b+c+d==4){n=1}else{n=n+1} test.set[1,]=c(a,b,c,d) test_data[n,,2] =c(a,b,c,d,as.vector(predict(quant.reg,test.set))) } } } } test.set sample rank1 rank2 rank3 rank4 2 1 1 1 1 5 6 9 9 10 8 14 6 13 8 12 14 11 10 1 16 6 6 6 9 18 5 7 6 8 quant.reg is a "lm" class Error in test_data[n, , 2] <- c(a, b, c, d, predict(quant.reg, : number of items to replace is not a multiple of replacement length  Any help regarding this error is appreciated. Since I'm new to R, I'm also open to a better approach.