0
我有以下簡單的代碼,我面對以下錯誤,任何人都可以幫我弄清楚嗎?它基本上應該計算使用兩個向量的得分和b輸入:如果循環參數長度爲零,錯誤
Error in if (b[i] == 1) { : argument is of length zero
我的代碼是:
require("Matrix")
# input vectors
a<-c(0.01,0.02,0.09,0.81,0.54,0.04,0.05,0.11,0.44,0.08,0.03,0.06,0.07,0.22,0.21,0.34,0.77,0.89,0.45,0.13,0.32,0.42,0.21,0.73,0.66,0.88)
b<-c(0,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0)
#order the singificance vector together with pathway vector with increasing P-value
sort(a, decreasing=F)
b[order(a,decreasing =F)]
GSEA<-function(a,b){
m=length(a)
l=nnzero(b)
score<-c()
for (i in a){
if(b[i]==1){
score= + (m-l)
}else{score=score-l}
}
}
total<-c()
total.x<-c(1:m)
total.y<-score