MPR1 <- MPR1 %>%
mutate(
Dispensed = Dispensed / 365, #calculation for a period of 1 year)
Dispensed = case_when(
Drug == "Imatinibe 100mg" ~ Dispensed / 2,#referring to two tablets per day. In the case of 3 tablets, divide by 3, and so on.
Drug == "Dasatinibe 20mg" ~ Dispensed / 2,
Drug == "Nilotinibe 200mg" ~ Dispensed / 4,
Drug == "Imatinibe 400mg" ~ Dispensed,
Drug == "Dasatinibe 100mg" ~ Dispensed
)
) %>%
group_by(Medical.record, Drug) %>%
summarise(
Porcentagem = ifelse(sum(Dispensed) > 100, 100, round(sum(Dispensed), 2) * 100),
.groups = "drop"
) %>%
mutate(Porcentagem = ifelse(Porcentagem > 100, 100, Porcentagem),
Porcentagem = format(Porcentagem, digits = 2, nsmall = 2, scientific = FALSE) %>%
paste0("%"))