Count occurrences of each value in a real column
Returns a data frame with two columns: unique values and their counts
@param[in] df The data frame instance @param[in] col_index Column index (1-based) @return Data frame with columns “Value” and “Count”
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
integer, | intent(in) | :: | col_index |
function df_value_counts_real(df, col_index) result(counts_df) type(data_frame), intent(in) :: df integer, intent(in) :: col_index type(data_frame) :: counts_df real(rk), dimension(:), allocatable :: col, unique_vals integer(ik), dimension(:), allocatable :: counts integer :: i, j unique_vals = df_unique_real(df, col_index) allocate (counts(size(unique_vals))) counts = 0 col = df_get_col_real(df, col_index) do i = 1, size(col) do j = 1, size(unique_vals) if (abs(col(i) - unique_vals(j)) < 1.0e-10_rk) then counts(j) = counts(j) + 1 exit end if end do end do call counts_df % new() call df_append_real(counts_df, unique_vals, "Value") call df_append_integer(counts_df, counts, "Count") end function df_value_counts_real