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)
}
Datatest = Datatest[,-1]
就删除第一列
-2就删除第二列
依次类推
Datatest[-1,]就是删除第一行