jeudi 2 mars 2017

What is a faster alternative for if else loops in R

I am applying the following code

x <- rep(NA, t)
for(i in 1:length(t)){
if(Close[i] > sma[i]+0.0017){
x[i] <- 1}
else{x[i] <- 0}
}

but it takes almost 30 minutes to process this code. How can I rewrite it in more efficient way?

Aucun commentaire:

Enregistrer un commentaire