Skip to content

Instantly share code, notes, and snippets.

@thomasjensen
Created December 21, 2011 08:05
Show Gist options
  • Save thomasjensen/1505156 to your computer and use it in GitHub Desktop.
Save thomasjensen/1505156 to your computer and use it in GitHub Desktop.
vectorized function for getting outliers in rows of a matrix
data <- cbind(rnorm(100),rnorm(100),rnorm(100))
outlierMat <- function(mat) {
m <- rowMeans(mat)
devs <- abs(mat - m)
val <- apply(mat, 1, max)
pos <- which(mat == val, arr.ind = TRUE)
out <- cbind(pos,val)
return(out)
}
out <- outlierMat(data)
out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment