Hi,

I have R code like so:

num.columns.back.since.last.occurence <- function(m, outcome) {
        nrows <- dim(m)[1];
        ncols <- dim(m)[2];
        res <- matrix(rep.int(0, nrows*ncols), nrow=nrows);
        for(row in 1:nrows) {
                for(col in 2:ncols) {
                        res[row,col] <- if(m[row,col-1]==outcome) {0} else 
{1+res[row,col-1]}
                }
        }
        res;
}

but on the very large matrices I apply this the execution times are a
problem. I would appreciate any help to rewrite this with more
"standard"/native R functions to speed things up.

--
View this message in context: 
http://r.789695.n4.nabble.com/Speeding-up-accumulation-code-in-large-matrix-calc-tp4417911p4417911.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org 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.

Reply via email to