Hi,

I am running the following loop, but it takes hours to run as n is big. Is 
there any way "apply" can be used? Thanks.
### Start
    nclass <- dim(data)[[2]] - 1
    z <- matrix(0, ncol = nclass, nrow = nclass)
    n <- dim(data)[[1]]
    x <- c(1:nclass)
# loop starts
for(loop in 1:n) {
        r <- data[loop, 1:nclass]
        classified <- x[r == max(r)]
       
        truth <- data[loop, nclass + 1]
        z[classified, truth] <- z[classified, truth] + 1
    }
# loop ends


             
---------------------------------

        [[alternative HTML version deleted]]

______________________________________________
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