Rank values in a real column
Assigns rank positions to each value in the column (1 = smallest/largest)
@param[in] df The data frame instance @param[in] col_index Index of column to rank @param[in] ascending Optional ranking direction (default: .true. for ascending) @return Array of integer ranks corresponding to each row
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
integer, | intent(in) | :: | col_index | |||
logical, | intent(in), | optional | :: | ascending |
function df_rank_real(df, col_index, ascending) result(ranks) type(data_frame), intent(in) :: df integer, intent(in) :: col_index logical, intent(in), optional :: ascending integer(ik), dimension(:), allocatable :: ranks real(rk), dimension(:), allocatable :: col, sorted_col type(column) :: data_col integer :: i, j, n logical :: asc asc = .true. if (present(ascending)) asc = ascending data_col = df % get_data_col(col_index) col = data_col % getr() n = size(col) allocate (ranks(n)) allocate (sorted_col(n)) sorted_col = col call quick_sort_real(sorted_col, 1, n) if (.not. asc) then ! Reverse for descending sorted_col = sorted_col(n:1:-1) end if do i = 1, n do j = 1, n if (abs(col(i) - sorted_col(j)) < 1.0e-10_rk) then ranks(i) = j exit end if end do end do deallocate (sorted_col) end function df_rank_real