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 =
using dplyr
you can try:
require(dplyr)
df2 %>% mutate(Date = as.Date(paste("1", Week, Year, sep = "-"), format = "%w-%W-%Y"),
Year_Mon = format(Date,"%Y-%m")) %>% group_by(Year_Mon) %>%
summarise(result = median(Measurement))
As @djhrio pointed out, Thursday is used to determine the weeks in a month. So simply switch paste("1",
to paste("4",
in the code above.