migrate {migrate} | R Documentation |
Summarize the migration of a data frame
Description
migrate()
summarizes the transition amount (or percentage) of a numeric
variable from each beginning credit risk state category to each ending credit
risk state, given a data frame input.
Usage
migrate(
data,
id,
time,
state,
metric = NULL,
percent = TRUE,
fill_state = NULL,
verbose = TRUE
)
Arguments
data |
A data frame or data frame extension (e.g., a tibble or
data.table) containing a minimum of three (3) column variables representing
a time, a credit risk state, 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 unique |
id |
The column variable of the |
time |
The column variable of in the |
state |
The column variable of the |
metric |
(Optional) The column variable of type "numeric" in the |
percent |
If |
fill_state |
(Optional) A value (e.g., a character string such as "No
Rating" or "NR") to be used as the filler |
verbose |
If |
Value
A data frame containing three (3) column variables representing the unique combinations of starting & ending credit risk states and the calculated migration observed during the period.
Examples
# Return the percent migration of the number of credit facilities
migrate(
data = mock_credit,
id = customer_id,
time = date,
state = risk_rating
)
# Return the absolute migration in `principal_balance`
migrate(
data = mock_credit,
id = customer_id,
time = date,
state = risk_rating,
metric = principal_balance,
percent = FALSE
)
# Provide a filler `state` value when a unique `id` is missing a timepoint
migrate(
data = head(mock_credit, n = 995), # drop the last 5 observations
id = customer_id,
time = date,
state = risk_rating,
fill_state = "NR",
percent = FALSE
)