samedi 15 août 2020

how to combine the output in the loop with a if statement in r

Here is my code:

dataall=merge(x = bootranked, y = originalE, by=0, all.x = T, all.y = F)

#finaloutput=rep(NA,1000)
#magic_for(print, silent = TRUE)
for (i in 1:ksign){
if (ksign<=ksign1){
  bootk[i]=newdata1[i,1]-1/ksign*sum(dataall[,2]-dataall[,4])
  #print(bootk)
} else {
  bootk[i]=newdata1[i,1]-1/ksign1*sum(dataall[,2]-dataall[,4])
  #print(bootk1)
}
  print(bootk)
} 

the dataall is like this:

Row.names       V1.x         V2.x         V1.y         V2.y
1        x1.1  0.4000122 1.681746e-03  0.363914590 0.0868910925
2      x1.100  0.4949200 1.047375e-04  0.255390161 0.2269756532
3      x1.101  0.3298167 9.774672e-03  0.301369197 0.1539540373
4      x1.102  0.4242175 8.993392e-04  0.785578625 0.0002499821
5      x1.104  0.4653682 3.290099e-04 -0.064057636 0.7625579183
6      x1.105  0.7944234 7.967662e-10  0.432133351 0.0422609801
7      x1.106  0.4931689 1.274969e-04  0.177176707 0.4001823568
.....
Showing 1 to 15 of 542 entries, 5 total columns

newdata1 is like:

     [,1]         [,2]
x1.631  0.7276578 1.841870e-08
x1.655  0.6736610 1.631133e-07
x1.371  0.6644818 2.323429e-07
x1.105  0.6571262 3.185964e-07
x1.151  0.6272119 1.099948e-06
x1.56   0.5919371 3.952747e-06
x1.102  0.5811969 5.572360e-06
x1.494  0.5705831 9.095983e-06
x1.429  0.5664096 9.758770e-06
......
Showing 1 to 15 of 564 entries, 2 total columns

ksign and ksign1 are just 2 numbers, depends on the simulation. I want to have the combine version output of the bootk, it should be look like a one column dataframe, what should I do?

Aucun commentaire:

Enregistrer un commentaire