I have a list of bank transactions for different customers and each transaction has a transaction time.
I need to group the transactions into 24 bins, where each bin represents a one-hour interval, e.g: 8-9 am, 9-10 am, 22-23pm, and so on for 24 hours.
So first I want to assign a bin number to each hour interval for each transaction, e.g: 8-9 am = "1", 9-10am = "2", and so on till 24.
And then I will look at the frequency of each bin for each customer. e.g. is how many times does a customer shop between 4-5pm and so on for all the bins.
I have attached a screenshot of my what the data looks like.
I used
as.POSIXct(Customers$TRANSACTION.TIME,format="%H:%M:%S")
but the output it gives me looks like this
The code I'm looking for should be something like this:
Customers$timebins = ifelse(
Customers$TRANSACTION.TIME >= 8 & Customers$TRANSACTION.TIME < 9,
1,
ifelse(
Customers$TRANSACTION.TIME >= 9 &
Customers$TRANSACTION.TIME < 10,
2,
ifelse(........
)
and so on.