Last chance! 50% off unlimited learning
Sale ends in
data(featForge_transactions)
# Example 1: Aggregate outgoing transactions (amount < 0) on a monthly basis.
aggregate_applications(featForge_transactions[featForge_transactions$amount < 0, ],
id_col = 'application_id',
amount_col = 'amount',
time_col = 'transaction_date',
ops = list(
avg_momnthly_outgoing_transactions = mean,
last_month_transactions_amount = function(x) x[length(x)],
# In the aggregated numeric vector, the last observation represents the most recent period.
last_month_transaction_amount_vs_mean = function(x) x[length(x)] / mean(x)
),
period = 'monthly',
observation_window_start_col = 'obs_start',
scrape_date_col = 'scrape_date'
)
# Example 2: Aggregate transactions by category and direction.
featForge_transactions$direction <- ifelse(featForge_transactions$amount > 0, 'in', 'out')
aggregate_applications(featForge_transactions,
id_col = 'application_id',
amount_col = 'amount',
time_col = 'transaction_date',
group_cols = c('category', 'direction'),
ops = list(
avg_monthly_transactions = mean,
highest_monthly_transactions_count = max
),
period = 'monthly',
period_agg = length,
observation_window_start_col = 'obs_start',
scrape_date_col = 'scrape_date'
)
# Example 3: Aggregate using a custom numeric period:
# 30-day cycles for 3 consecutive cycles (i.e., the last 90 days).
aggregate_applications(featForge_transactions,
id_col = 'application_id',
amount_col = 'amount',
time_col = 'transaction_date',
ops = list(
avg_30_day_transaction_count_last_90_days = mean
),
period = c(30, 3),
period_agg = length,
observation_window_start_col = 'obs_start',
scrape_date_col = 'scrape_date'
)
# Example 4: Aggregate transactions without time segmentation.
aggregate_applications(featForge_transactions,
id_col = 'application_id',
amount_col = 'amount',
ops = list(
total_transactions_counted = length,
total_outgoing_transactions_counted = function(x) sum(x < 0),
total_incoming_transactions_counted = function(x) sum(x > 0)
),
period = 'all'
)
Run the code above in your browser using DataLab