lundi 22 décembre 2014

Natural log e AND if statement in r

I'm trying to use an IF statement in one matrix (p.values1) to take out (>0.05) or leave the value of a correspondent cell in a second matrix (g1) of the same dimensions.



for (i in 1:C){
for(t in 1:C){
if (t==i){g1[t,i]<-NULL}
else{ if(p.values1[t,i]>0.05){g1[t,i]<-NULL}
else{g1[t,i]<-g1[t,i]}
}
}
}


However, whenever a cell has a natural log (e) value, it always assumes it is >0.05. An example is shown below. Column [,1] is p.values, [,2] are original g1 values, [,3] are assigned values after the loop.



[,1] [,2] [,3]
[1,] "0.415" "0.306475822679704" "0"
[2,] "0.4246" "0.318337744764897" "0"
[3,] "0.6342" "-0.189794395570932" "0"
[4,] "0.2124" "0.46622696563966" "0"
[5,] "0.3756" "-0.337631466288917" "0"
[6,] "0.6758" "0.159654159262105" "0"
[7,] "0.1946" "0.48001275352272" "0"
[8,] "0.2296" "0.44491969530013" "0"
[9,] "0.4895" "-0.258847065520103" "0"
[10,] "0.9955" "0.00187842355825314" "0"
[11,] "0.2088" "0.463911110088195" "0"
[12,] "0.4248" "-0.296462780404452" "0"
[13,] "0.8015" "0.0969894401327047" "0"
[14,] "0.9444" "-0.0265849681752223" "0"
[15,] "1e-04" "0.941935155205701" "0"
[16,] NA "1" "0"
[17,] "3e-04" "0.937622922462752" "0"
[18,] "0.4381" "0.293218162854413" "0"
[19,] "0.8659" "0.0625072510568426" "0"
[20,] "0.389" "-0.32595557253288" "0"
[21,] "0.1815" "-0.481217487083996" "0"
[22,] "0.2908" "-0.387323216158986" "0"
[23,] "0.6791" "0.153759979688198" "0"
[24,] "0.0158" "0.784226372010803" "0.784226372010803"


The values [15,1] e [17,1] are >0.05, but are set as NULL instead of just leaving the original g1 value. Any suggestions on how to make this loop account for 'e' values or to get around this?


Thanks in advance,


Aucun commentaire:

Enregistrer un commentaire