I have a data set of ATM IDs that are coded with dummy variables that tells us whether the ATM is open or closed. The goal is to generate a new column (type) that categorizes each ATM based on its opening/closure behavior. In this data, 1 in the dummy variable tells us that the ATM is open, and 0 tells us that the ATMs is closed. Here is the data and expected output.
data <- tribble(
~atm_id, ~nov_2019, ~feb_2020, ~may_2020, ~aug_2020, ~nov_2020, ~type,
"xx1", 0, 0, 0, 0, 0, "A",
"xx2", 0, 1, 1, 1, 1, "B",
"xx3", 0, 0, 1, 1, 1, "B",
"xx4", 0, 0, 0, 1, 1, "B",
"xx5", 0, 1, 0, 1, 1, "C",
"xx6", 0, 1, 0, 1, 0, "C"
)
I am trying to mutate the type variable and categorize each type of opening/closure behavior.
- Type A - ATMs that closed in the first time period, and remained closed (all zeros)
- Type B - ATMs that closed in the first time period, eventually reopened, and have stayed open so far.
- Type C - ATMs that closed in the first time period, eventually reopened, and then closed again after reopening - i.e., (0, 1, 0, 1)
The month/year columns go up to 2022, and we will be adding more data later on, so the ideal the code is flexible to accommodate. However, these three are the basic types of opening/closure behaviors, and I need to capture them somehow using row-wise operations or some other method.