Add new row to matrix one by one

Viewed 50383

This is a simple problem, but for the life of me I cannot find the answer.

for (w in 1:47) {
    s <- w + 1;

    while(s < 49) {
        xx <- wcc(x$codes[w,], x$codes[s,], 20)
        C = matrix(rbind(w,s,xx), nrow=1128, ncol=3, byrow=TRUE)
        s <- s + 1;
    }
}

in this loop, I want to put the XX into matrix C one by one.

3 Answers

Here is an example where the matrix is created based on the pattern, which is the first row. The row to be included is X.

if (!exists("XM")) {
  XM = matrix(X, ncol = length(X))
} else
{
  XM = rbind(XM, X)
}

In the initialization, we need to remove XM (to be sure):

if (exists("XM")) rm("XM") 
Related