[R] R: "in-place" appending to a matrix.

culpritNr1 ig2ar-saf1 at yahoo.co.uk
Wed Oct 15 22:05:27 CEST 2008


Hello fellow R sufferers,

Is there a way to perform an appending operation in place?

Currently, the way my pseudo-code goes is like this

for (i in 1:1000) {
    if (some condition) {
        newRow <- myFunction(myArguments)
        X <- rbind(X, newRow)     #  <- this is the bottleneck!!
    }
}

As you can see, it works but as the matrix X gets the size of a few million
rows, the code runs very slow.

I am looking for something like the natively "in place" appending python
function called "append()" or the perl function "push". "In-place"
operations would allow me to do (in pseudocode)

for (i in 1:1000) {
    if (some condition) {
        newRow <- myFunction(myArguments)
        append(X, newRow)
    }
}

You see? I do not have to call and re-assign the giant X matrix every loop
cycle.

Any help?

Thank you,

Your culpritNr1



-- 
View this message in context: http://www.nabble.com/R%3A-%22in-place%22-appending-to-a-matrix.-tp20001258p20001258.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list