How to organize data from weeks to months?

Hi all! I'm really new to R and learning the basics. I've been practising with dplyr but came to a roadblock and would really appreciate the help.

So I have a dataset with columns ranging from "year", "eweek", "type of dengue" and "number" and I want to organize them just by "year", "month", "number".

The first challenge here is that each week there are 2 rows (because of 2 type of dengue rows) so I am thinking of adding the values of "number" together for each week.

The second challenge is to summarize the weeks into months.

(A sample picture of the data frame is attached for easier reference.)

Any kind folks can direct me to the best way to approach these problems? It seems a little complex for a newbie like me but would really like to learn.

Thank you in advance!

This isn't totally obvious, so this was a good stretch for me, too!

This is the thought process I think would work:

  1. convert year & week number into a date
  2. find the month from the date
  3. do a group_by(year, month, type_dengue) and summarize(sum()) to add up the values by month.

The first step is the hardest. This walkthrough seems to work: It looks like the format needs to be YYYY-W in order for it to parse.

The second step can use lubridate. Try using mutate(month = month(x)) to create a column for the month number.

Then, I bet you have enough dplyr skills to group_by and summarize from there.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.