def quantile(l, p):
    """Return p quantile of list l. E.g. p=0.25 for q1.

    See:
    http://rweb.stat.umn.edu/R/library/base/html/quantile.html

    """
    l_sort = l[:]
    l_sort.sort()
    n = len(l)
    r = 1 + (n - 1) * p
    i = int(r)
    f = r - i
    if i < n:
        result = (1 - f) * l_sort[i - 1] + f * l_sort[i]
    else:
        result = l_sort[i - 1]
    return result
