Sha256: 18a2dcabad2f5b0e4f1faede5882f1b4c4da8090bfbc5ecf0c0b64e20c996b36

Contents?: true

Size: 384 Bytes

Versions: 1

Compression:

Stored size: 384 Bytes

Contents

class Array
  def percentile p
    if p < 0 || p > 100
      nil
    else
      self.sort[((p.to_f / 100.0) * self.length.to_f) - 0.5]
    end
  end

  def interquartile_range
    self.percentile(75) - self.percentile(25)
  end

  def iqr
    self.interquartile_range
  end

  def midspread
    self.interquartile_range
  end

  def middle_fifty
    self.interquartile_range
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rstat-0.1.0 lib/rstat/core_ext/array/descriptive_statistics/dispersion/percentile.rb