I second @andresrcs, about more specific questions. I can make a general observation.
Ne réinvente pas la roue
There's stats::quantiles already
quantile returns estimates of underlying distribution quantiles based on one or two order statistics from the supplied elements in x at probabilities in probs. One of the nine quantile algorithms discussed in Hyndman and Fan (1996), selected by type, is employed.
All sample quantiles are defined as weighted averages of consecutive order statistics. Sample quantiles of type i are defined by:
Qi = (1 - γ) x[j] + γ x[j+1],
where 1 ≤ i ≤ 9, (j-m)/n ≤ p < (j-m+1)/n, x[j] is the jth order statistic, n is the sample size, the value of γ is a function of j = floor(np + m) and g = np + m - j, and m is a constant determined by the sample quantile type.
Sounds like you want Type 4.