首页 > 编程语言 > 详细

r语言 技巧总结

时间:2017-03-01 17:57:51      阅读:232      评论:0      收藏:0      [点我收藏+]

1.table函数返回众数,再转为dataframe

as.data.frame(table(x))

2.使用which 返回数组下标

which(rs.list=="rs1008507")

3.循环数值存储

(1)

M<-matrix(NA,6,6)
for(i in 0:6){
if(i<=2)
{for(j in (2-i):(6-i)) M[i,j]<-{( i*0.5+(j+3)+(i+j-2)*0.5+(4-(i+j-2))+3)}}
else
{for(j in 0:(6-i)) M[i,j]<-{( i*0.5+j+3+(i+j-2)*0.5+(4-(i+j-2))+3)}}}
M

(2)

entropy_c = c()
for (x in data_ip$ip){
mid_frame <- data_ua[which(data_ua$ip == x),]$cnt
data_ua <- data_ua[-which(data_ua$ip == x),]
entropy_i <- entropy(data = mid_frame , method = "sample")
entropy_c <- c(entropy_c , entropy_i)
}

 

 

 




r语言 技巧总结

原文:http://www.cnblogs.com/awishfullyway/p/6485227.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!