I have a matrix of size "n" and I want to create a new one in which the columns are sums of the original matrix, with some order in the sums. For example, if matrix A has 4 columns, then the new matrix should have 6 columns with the following info from the columns of A: 1+2, 1+3, 1+4, 2+3, 2+4, 3+4. If matrix A has 5 columns, then the new matrix has 10 columns: 1+2, 1+3, 1+4, 1+5, 2+3, 2+4, 2+5, 3+4, 3+5, 4+5
I thought of using a for loop: for (i in 1:n-1) { for (j in (i+1):n) { A[,i] + A[,j] } } but I don't know how to store the results so the new matrix has all the columns. I know the number of columns in the new matrix is given by n(n-1)/2. Any ideas? Thanks. Hiram ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.