Last active
December 20, 2016 14:22
-
-
Save teguhn/5c0f4b948b359720fe607d353f6e9ea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#returning vector without extreme/outlier values | |
rm.extreme <- function(v) { | |
q3<-quantile(v, .75) | |
q1<-quantile(v, .25) | |
iqr <- 1.5 * ( q3- q1) | |
sapply(v, function(x) { | |
x[x > (q1 - iqr) & x < (q3 + iqr)] | |
}) | |
} | |
#returning vector containing lower and upper limit of normal values | |
extreme.limit <- function(v) { | |
q3<-quantile(v, .75)[[1]] | |
q1<-quantile(v, .25)[[1]] | |
iqr <- 1.5 * ( q3- q1) | |
return(c((q1 - iqr),(q3 + iqr))) | |
} | |
#returning boolean if x is an extreme value of vector v | |
is_extreme <- function(v, x){ | |
lim <- extreme.limit(v) | |
if(x<lim[1]){return('extreme_bottom')} | |
else if(x>lim[2]){return('extreme_top')} | |
else{return('normal')} | |
} | |
#testing | |
tes.data <- rnorm(100) | |
extreme.limit(tes.data) | |
is_extreme(tes.data, 3) |
upha
commented
Dec 20, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment