R script for yearly and weekly analysis