Skip to content

Instantly share code, notes, and snippets.

@ShixiangWang
Created December 10, 2017 14:57
Show Gist options
  • Save ShixiangWang/48f0d2d5e2c4258cd0db9c9d6b5b5618 to your computer and use it in GitHub Desktop.
Save ShixiangWang/48f0d2d5e2c4258cd0db9c9d6b5b5618 to your computer and use it in GitHub Desktop.
按四分位数、均值或中位数分组,返回名称
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