My data is in a dataframe which has a structure like this:
df2 <- data.frame(Year = c(\"2007\"), Week = c(1:12), Measurement = c(rnorm(12, mean = 4, sd =
This can be done relatively simply in dplyr.
library(dplyr)
df2 %>%
mutate(Month = rep(1:3, each = 4)) %>%
group_by(Month) %>%
summarise(MonthlyMedian = stats::median(Measurement))
Basically, add a new column to define your months. I'm presuming since you don't have days, you are going to allocate 4 weeks per month? Then you just group by your Month variable and calculate the median. Very simple
Hope this helps