df_diff_integer Function

public function df_diff_integer(df, col_index) result(differences)

Calculate differences between consecutive rows (result has n-1 elements)

Returns an array where each element is the difference between consecutive values

@param[in] df The data frame instance @param[in] col_index Index of the column @return Array of differences with n-1 elements

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
integer, intent(in) :: col_index

Return Value integer(kind=ik), dimension(:), allocatable


Source Code

    function df_diff_integer(df, col_index) result(differences)
        type(data_frame), intent(in) :: df
        integer, intent(in) :: col_index
        integer(ik), dimension(:), allocatable :: differences

        integer(ik), dimension(:), allocatable :: col
        integer :: i, n

        col = df_get_col_integer(df, col_index)
        n = size(col)

        if (n < 2) then
            allocate (differences(0))
            return
        end if

        allocate (differences(n - 1))
        do i = 1, n - 1
            differences(i) = col(i + 1) - col(i)
        end do
    end function df_diff_integer