search for: examp_per

Displaying 1 result from an estimated 1 matches for "examp_per".

2017 Dec 13
3
inefficient for loop, is there a better way?
...be sped up on the true dataset. I would like to run a more efficient script many times adjusting the value of 'per'. ts <- 1:1000 examp <- data.frame(ts=ts, stage=sin(ts)) hi1 <- list() hi2 <- list() per <- 7 elev1 <- 0.6 elev2 <- 0.85 for(i in per:nrow(examp)){ examp_per <- examp[seq(i - (per - 1), i, by=1),] stg_hi_cond1 <- subset(examp_per, examp_per$stage > elev1) stg_hi_cond2 <- subset(examp_per, examp_per$stage > elev2) hi1 <- c(hi1, nrow(stg_hi_cond1)) hi2 <- c(hi2, nrow(stg_hi_cond2)) } examp$days_abv_0.6_in_last_7 &lt...