Created
December 10, 2017 14:57
-
-
Save ShixiangWang/48f0d2d5e2c4258cd0db9c9d6b5b5618 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
getID = function(exp_value, method){ | |
# compute threshold according to method parameter | |
if(method=="quartile"){ | |
symbol_stat <- summary(exp_value) | |
ths1 <- as.numeric(symbol_stat[2]) | |
ths2 <- as.numeric(symbol_stat[5]) | |
down_id <- names(exp_value[exp_value<=ths1]) | |
up_id <- names(exp_value[exp_value>=ths2]) | |
}else if(method=="mean"){ | |
ths <- mean(exp_value) | |
down_id <- names(exp_value[exp_value<=ths]) | |
up_id <- names(exp_value[exp_value>ths]) | |
}else if(method=="median"){ | |
ths <- median(exp_value) | |
down_id <- names(exp_value[exp_value<=ths]) | |
up_id <- names(exp_value[exp_value>ths]) | |
} | |
return(list(down_id, up_id)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment