For the case where one has to compute the outliers quickly, one could use the idea of Rob Hyndman and Mahito Sugiyama ( https://github.com/BorgwardtLab/sampling-outlier-detection , library(spoutlier), function qsp ) to compute the outliers as follows: library(spoutlier) rapidtsoutliers <- function(x,plot=FALSE,seed=123) { random.seed(seed) x <- as.numeric(x) tt <- 1:length(x) qspscore <- qsp(x) limit <- quantile(qspscore,prob=c(0.95)) score <- pmax((qspscore - limit),0) if(plot) { plot(x,type="l") x2 <- ts(rep(NA,length(x))) x2[score>0] <- x[score>0] tsp(x2) <- tsp(x) points(x2,pch=19,col="red") return(invisible(score)) } else return(score) }