1
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.

  • 1
    Can you provide expected dataframe output? – zx8754 May 11 '23 at 14:39
  • 1
    @aleksandar_m this is unclear - you say you want "a table with `Types` as rows, and `MondayDay`, `MondayNight`, ... columns" - this is what you currently have. Do you want to convert the yes/no to 1/0? Could you edit your question to provide some clarity? – jpsmith May 11 '23 at 14:58
  • @jpsmith I hope it is now better with example of table. If try to converting yes/no into 1/0. However, did not find final solution. For me, 1/0 is fine if it provides the table such I present. Thanks. – aleksandar_m May 11 '23 at 15:15
  • @zx8754 thank you interesting. Yes, I have put desirable table. – aleksandar_m May 14 '23 at 06:20

0 Answers0