time_frame <- max(data$Dateofcollection, na.rm = T) %m-% months(12) Ensure that Dateofcollection does not have errors in which case this analysis will be wrong.