0

I'm confused with an exercise that i'm working on in R. I'm just a beginner in R

the instructions is to Use dplyr to manipulate the data so that you have the proportion immunised (i.e. Immunised divided by Eligible) for each DHB, for each Age, and each Date. Save the result so you can use it for the remaining questions. You should end up with a data frame containing variables for DHB, Date, Age and Proportion with 4834 observations.

But I don't understand how to do this but this is what i've tried

```{r}
vacc %>% mutate(Proportion = Immunised/DHB(vacc))

vacc %>% select(DHB, Date, Age, Proportion)
```

but it gave me this error

Error: Problem with `mutate()` input `Proportion`. x could not find function "DHB" i Input `Proportion` is `Immunised/DHB(vacc)`.

can someone please help me

1 Answers1

0

DHB is a column in the dataframe, however, you are using it as function.

You can group_by DHB, Age and Date and calculate ratio between Immunised and Eligible.

library(dplyr)
vacc %>%  group_by(DHB, Age, Date) %>% mutate(Proportion = Immunised/Eligible)

Perhaps, I think this would work too :

vacc %>%  mutate(Proportion = Immunised/Eligible)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213