Q:

colsum conditions in R?

I have this data that is split by week and would like to change this into monthly and/or quarterly data. Is there a condition that I can use that will sum column data based on dates or weeks? I am unsure how to do it based on weeks given I have data from 1962-2016 and do not want to combine all weeks. Below is how my data frame is set up, any suggestions greatly appreciated.

Okay so this is filtered by week, and I have years with 52 or 53 weeks. The suggested solution does seem to fix these even though some dates are the ending dates and some fall in the previous year. If I can create a new column by Year and Month and sum column values in columns 7-13 (by column not row) 

A:

library(dplyr)
# First create new variable for just the month and year
df$Month_Yr <- format(as.Date(df$Date), "%Y-%m")
# Then group by (dplyr) the months and sum over intended variable
df %>% group_by(Month_Yr) %>% summarise(sum_pideaths = sum(pideaths, na.rm = TRUE))

Note: this will only sum the column pideaths. If you want to sum all of the columns, first select the numeric columns and then use summarise_all():
df %>% select(Month_Yr,**numeric_cols**) %>% group_by(Month_Yr) %>% summarise_all(funs(sum = sum(na.rm = TRUE)))

