Learn R Programming

migrate (version 0.2.0)

migrate: Summarize the migration of a data frame

Description

`migrate()` summarizes the transition amount (or percentage) of a continuous variable from each beginning credit risk rating category to each ending credit risk rating, given a data frame input.

Usage

migrate(data, date, rating, metric, percent = FALSE, method = "start")

Arguments

data

A data frame or data frame extension (e.g., a tibble or data.table) containing a minimum of four (4) column variables representing a date, a credit risk rating, a (continuous) metric, and an ID identifying the credit facility (we would expect to see most unique values in this column variable appear twice in the dataset; once at the first date and again at the second date, unless the credit only existed at one of those two dates).

date

A symbol or string, representing the column variable of the `data` data frame argument that contains the two unique date values.

rating

A symbol or string, representing the column variable of the `data` data frame argument that contains the credit risk rating values.

metric

A symbol or string, representing the column variable of the `data` data frame argument that contains the continuous metric values.

percent

If `TRUE`, will compute the percentage change in the continuous metric instead of just using the absolute difference.

method

One of c("start", "end"). If "start" (this is the default), this will migrate the values in the `metric` column variable at the earlier date value from the `date` column variable. If "start" (this is the default), this will migrate the values in the `metric` column variable at the later date value from the `date` column variable.

Value

A data frame containing three (3) column variables representing the unique combinations of starting & ending credit risk ratings and the migrated difference in the continuous metric.

Examples

Run this code
# NOT RUN {
# Return the absolute migration in `principal_balance`
mock_credit %>%
  migrate(
    date = date,
    rating = risk_rating,
    metric = principal_balance
  )

# Return the percent migration in `principal_balance` while using the "end"
# method for which period's metric values to migrate
mock_credit %>%
  migrate(
    date = date,
    rating = risk_rating,
    metric = principal_balance,
    percent = TRUE,
    method = "end"
  )

# }

Run the code above in your browser using DataLab