I have a data frame like below
doctor user Hour weekday
1 d1 u1 07_08 Wednesday
2 d1 u2 07_08 Wednesday
3 d1 u2 07_08 Wednesday
4 d1 u2 07_08 Wednesday
5 d1 u3 07_08 Wednesday
6 d1 u3 07_08 Wednesday
I want get number of users group by doctor ,hour and weekday. I have used for loop for that but is there anyway to get with dplyr group by function?
I have tried like below:
for(i in 1:length(unique(d$doctor)){
get unique doctors data
for(j in 1:length(unique(d$weekday)){
get weekday data for that doctor
for(k in 1:length(unique(d$Hour)){
h1=get hour data for that weekday and doctor
no_of_users <- nrow(unique(h1$users))
}
}
}
Is there any way to do that without using loops? Thank you.