[R] How to speed up a double loop?

jeff6868 geoffrey_klein at etu.u-bourgogne.fr
Tue Mar 3 11:49:20 CET 2015

I tried another faster way which seems to do the trick right now:

    test <- function(x){
    st1 <- numeric(length(x))
    temp <- st1[1]
    for (i in 2:(length(x))){ 
        if((!is.na(x[i])) & (!is.na(x[i-1]))& (abs((x[i])-(temp)) >= 15)){
    st1[i] <- 1
    } } 

    myts[,2] <- apply(as.data.frame(myts[,1]),2,test)  
    myts[,2] <- as.numeric(myts[,2])

Thanks anyway for your help!

View this message in context: http://r.789695.n4.nabble.com/How-to-speed-up-a-double-loop-tp4704054p4704112.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list