Data Manipulation: Dynamic observation Drop

I am working on credit line assimilation data.

df_01 <- data.frame(
  user_id = c(1,1,1,1,1,1,1,1,1,2,2),
  var_type = c("withdraw","repaid","repaid","withdraw","repaid","repaid","repaid","withdraw","repaid","withdraw","repaid"),
  withdraw_id = c("u1_w1","u1_w1","u1_w1","u1_w2","u1_w2","u1_w2","u1_w2","u1_w3","u1_w3","u2_w1","u2_w1"),
  repaid_id = c("","u1_w1_r1","u1_w1_r2","","u1_w2_r1","u1_w2_r2","u1_w2_r3","","u1_w3_r1","","u2_w2_r1"),
  amt = c(-50,30,20,-60,20,30,10,-40,50,-30,10),
  credit_limit = c(100,100,100,100,100,100,100,100,100,50,50),
  running_balance = c(50,80,100,40,60,90,100,60,110,40,40),
  new_credit_limit = c(50,50,50,50,50,50,50,50,50,40,40),
  new_running_balance = c(0,30,50,-10,NA,NA,NA,10,60,0,40),
  drop_obs_flag = c(0,0,0,1,1,1,1,0,0,0,0)


  • var_type: has two types i.e withdraw, repaid
  • repaid id is associated with withdraw_id

we are trying to see, if we allotted different credit line to users, how will it affect our business

Objective: as per new credit line, if withdraw amount is greater than pevious running balance for a user_id, we have to drop all rows associated with that withdraw_id. i.e last columns

  • remarks_1: if the earlier withdraw obs is dropped, then we have to check the next withdraw id (it's in loop) for that user_id,
  • remarks_2: last 2 columns, new_running_balance and drop_obs_flag is output variable

Kindly guide me how to approach it. thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.