1
After finding a value of a calculation I need to compare if this value is equal to any of the first column of the table below (percentile), if it is equal, the corresponding value will be selected but that of the second column (values). And if it’s not the same, I have to interpolate between the two values closest to which it lies.
For example: I found the value equal to 0.1 and I will compare it with the first column of the table and in this case, the value corresponding to it in the second column would be 0.0158. But if the value was 0.93, I would have to interpolate between 2,706 and 3,841 which are the values corresponding to 0.90 and 0.95.
The table is as follows:
tabelaq <- data.frame(percentil=c(0.005,0.01,0.025,0.05,0.1,0.25,0.75,0.90,0.95,0.975,0.99,0.995),
valores=c(0.0000393,0.000157,0.000982,0.00393,0.0158, 0.102,1.323,2.706,3.841,5.024,6.635,7.879))
I tried logical conditions with for and if, but it’s giving error. I tried subset(tabelaq,percentil==t, select = valores)
inside if
and did not give.
I’m trying on the R.
Can anyone suggest me an idea?
God, you saved me so much. God bless you! Regarding the interpolation, I thought about the approx function, it performs the linear interpolation, hence it would be approx(table[,1]l,table[,2], xout=0.9875). xout is the value of x to be interpolated which in this case would be x (xout=x). Gratitude!
– Josiane Souza