Name <- c("Nick", "Bill", "Maria", "Ben", "Tina")
Type <- c("general", "specialized", "er", "specialized", "general")
MondayDay <- c("yes", "yes", "yes", "yes", "yes")
MondayNigth <- c("no", "no", "yes", "no", "no")
ThuesdayDay <- c("no", "yes", "yes", "yes", "yes")
ThuesdayNigth <- c("no", "no", "yes", "no", "no")
WednesdayDay <- c("no", "no", "no", "yes", "no")
WednesdayNight <- c("no", "yes", "yes", "yes", "no")
df <- data.frame(Name, Type, MondayDay, MondayNigth, ThuesdayDay, ThuesdayNigth, WednesdayDay, WednesdayNight)
df
The dataset is very simple. It is in the wide format. I have names of facilities (df$Name), their type (df$Type). Each facility send me a schedule data. Yes in MondayNight means it works during Monday night, for example. No, of course means opposite. I need to make a table with Types as rows and MondayDay, MondayNight... columns. The cell should contain number of facilities of specific type working on MondayNight, MondayDay... and percentage regarding total number of facilities such type. I struggle a lot, pivoting, but did not make anything further.
Thanks.
Facility type | Monday day | Monday night | Tuesday day | Tuesday night | Wednesday day | Wednesday night | Total |
---|---|---|---|---|---|---|---|
general | 2(100%) | 0 (0%) | 1 (50%) | 0 (0%) | 0 (0%) | 0 (0%) | 2 |
specialized | 2(100%) | 0 (0%) | 2 (100%) | 0 (0%) | 1 (50%) | 2 (100%) | 2 |
er | 1(100%) | 1 (100%) | 1 (100%) | 1 (0%) | 0 (0%) | 1 (0%) | 1 |
I hope this is more illustrative. If you suggest plot that present same, it is also fine for me. Thanks all.