

quantile {base}                              R Documentation

_S_a_m_p_l_e _Q_u_a_n_t_i_l_e_s

_D_e_s_c_r_i_p_t_i_o_n_:

     The generic function `quantile' produces sample quan-
     tiles corresponding to the given probabilities.  The
     smallest observation corresponds to a probability of 0
     and the largest to a probability of 1.

_U_s_a_g_e_:

     quantile(x, probs=seq(0, 1, 0.25), na.rm=FALSE, names = TRUE)

_D_e_t_a_i_l_s_:

     A vector of length `length(probs)' is returned; if
     `names = TRUE', it has a `names' attribute.

     `quantile(x,p)' as a function of `p' linearly interpo-
     lates the points ( (i-1)/(n-1), ox[i] ), where `ox <-
     order(x)' (the ``order statistics'') and `n <-
     length(x)'.

     This gives `quantile(x, p) == (1-f)*ox[i] + f*ox[i+1]',
     where `r <- 1 + (n-1)*p', `i <- floor(r)', `f <- r - i'
     and `ox[n+1] :=  ox[n]'.

_E_x_a_m_p_l_e_s_:

     quantile(x <- rnorm(1001))# Extremes & Quartiles by default
     quantile(x,  probs=c(.1,.5,1,2,5,10,50)/100)

     n <- length(x) ## the following is exact, because 1/(1001-1) is exact:
     all(abs(sort(x) == quantile(x, probs = ((1:n)-1)/(n-1), names=F)))# TRUE

     n <- 777
     ox <- sort(x <- round(rnorm(n),1))# round() produces ties
     ox <- c(ox, ox[n]) #- such that ox[n+1] := ox[n]
     p <- c(0,1,runif(100))
     i <- floor(r <- 1 + (n-1)*p)
     f <- r - i
     all(abs(quantile(x,p) - ((1-f)*ox[i] + f*ox[i+1])) < 20*.Machine$double.eps)

