R语言实现基本的rank划分

  • A+
所属分类:R语言

实现目的是数据进行区间划分(<_0_>)

R语言实现基本的rank划分

  1. #Code:
  2. library(DBI)
  3. library(ROracle)
  4. drv=dbDriver('Oracle')
  5. conn=dbConnect(drv,'test','test','192.100.10.10:1521/ZNJT')
  6. # get the flux of the current time (hour)
  7. rs=dbSendQuery(conn,"select * from dw_fact_flux where gcsj=to_char(sysdate,'yyyymmdd')-30000+900+8 
  8.  and sd=to_char(sysdate,'hh24')")
  9. data=fetch(rs)
  10. data=as.matrix(data)
  11. #get the count,mean,min,max,threshold,rank
  12. rownum=nrow(data)
  13. minval=min( as.numeric(data[,12]))
  14. meanval= mean(as.numeric(data[,12]))
  15. maxval=max( as.numeric(data[,12]))
  16. threshold1=(minval+meanval)/2
  17. threshold2=meanval
  18. threshold3=(meanval+maxval)/2
  19. # According to the scope of grouping
  20. rankval=cut(as.numeric(data[,12]),c(minval-1,threshold1,meanval,threshold3,maxval),labels = c("1","2","3","4"))
  21. datae=as.data.frame(cbind(data,rankval))
  22. dbWriteTable(conn,'DW_ACD_HDZT',datae, row.names = F, append = TRUE)
  23. dbDisconnect(conn)

注意:

1、datae=as.data.frame(cbind(data,rankval)) 如何换成datae=as.data.frame(cbind(data,RANKVAL))则会出现顺序混乱

2、表名要使用大写,datae转换as.data.frame

误差分位数的默示有效估计与\ 自回归时间序列的预测区间
深入浅出数据分析(中文版)
R语言神经网络模型银行客户信用评估数据
R语言实战(中文完整版)

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: