r - How to get the 95th and 5th percentiles separately? -


i have data (e.g.d , di) want calculations.

data:

d= 1:20 xi= 2:21 

i use equation(using 95th , 5th percentiles separately both d , xi):

          res= d(95th)-d(5th)/xi(95th)+xi(5th)           res2= res + xi(5th) 

we 95th , 5th percentiles using function(provided users of stackoverflow):

   fun <- function(x){ quantiles <- quantile( x, c(.05, .95 ) ) x[ x < quantiles[1] ] <- quantiles[1] x[ x > quantiles[2] ] <- quantiles[2] x                   } 

but not apply case want use 95th , 5th percentiles separately in equation above.any ideas please.

is looking for?

your_fun <- function(x,y){     qx <- quantile(x,c(.05,.95))     qy <- quantile(y,c(.05,.95))     out <- diff(qx)/diff(qy)     out2 <- out + qy[1]      names(out) <- null     names(out2) <- null     list(res=out,res2=out2) }  your_fun(d,xi) 

which gives

$res [1] 1  $res2 [1] 3.95 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -