I have a data frame like below.
Note: This is the sample data of my data.
data:
id user time1 time2 time3
1 user1 07:52 08:34 08:43
2 user2 08:14 10:09 10:22
3 user3 07:43 09:29 09:44
4 user4 09:36 10:34 11:05
Now I want to check how many active users are available at the time 09:36. I have wrote condition like below to get active users at the time 09:36.
for(k in 1:nrow(data)){
k=4
active_users_data <- subset(data,(data$time2 < data$time1[k] &
data$time3> data$time1[k]))
}
output :
id user time1 time2 time3
3 user3 07:43 09:29 09:44
But I need output format like below:
id time1 time2 time3 user1 user2 user3 user4
3 07:43 09:29 09:44 0 0 1 0
That is if user3 active at that point of time I need to get 1 in user3 column .How can i achieve the output like above? If two users are active at that point of time I need to get 1 corresponding users column.Please,suggest me ideas. I have to do this for large data set.