Method: Array#value_counts

Defined in:
ext/enumerable/statistics/extension/statistics.c

#value_counts(normalize: false, sort: true, ascending: false, dropna: true) ⇒ Hash

Returns a hash that contains the counts of values in ary.

This method treats nil and NaN, the objects who respond true to nan?, as the same thing, and stores the count of them as the value for nil.

Returns:

Parameters:

  • normalize (false, true)

    If true, the result contains the relative frequencies of the unique values.

  • sort (true, false)

    Sort by values.

  • ascending (false, true)

    Sort in ascending order.

  • dropna (true, false)

    Don't include counts of NAs.

Returns:

  • (Hash)

    A hash consists of the counts of the values



2130
2131
2132
2133
2134
# File 'ext/enumerable/statistics/extension/statistics.c', line 2130

static VALUE
ary_value_counts(int argc, VALUE* argv, VALUE ary)
{
  return any_value_counts(argc, argv, ary, ary_value_counts_without_sort);
}