rubysciruby

What gem to use to calculate percentile in Ruby?


In python, I can do this by using python, as in How do I calculate percentiles with python/numpy?

import numpy as np
a = np.array([1,2,3,4,5])
p = np.percentile(a, 50) 

I want to know what is the convenient way in 2018 to calculate percentile in Ruby?


Solution

  • That is few lines function, developer can write it by his own in 2018. But you can check descriptive_statistics gem.

    require 'descriptive_statistics'
    data = [1,2,3,4,5]
    data.percentile(50)