Tidying Time Intervals for Plotting a Histogram in R
This was a x-post. There is a great solution over here, where I originally asked the question.


  If I understand your problem, you'll want something like this:

bottom &lt;- seq(1750, 2010, 5)
library(dplyr)
new_df &lt;- mlt.mx.info %&gt;%
  arrange(Year) %&gt;%
  mutate(year2 = as.numeric(substr(Year, 6, 9))) %&gt;%
  mutate(new_year = paste0(bottom[findInterval(year2, bottom)], "-",(bottom[findInterval(year2, bottom) + 1] - 1)))
View(new_df)

  
  So what this does, it creates bins, and outputs a new column
  (new_year) that is the bottom of the bin. So everything from 1750-1754
  will correspond to a new value of 1750-1754 (in string form; the
  original is an integer type, not sure how to fix that). Does this do
  what you want? Double check the results, but it looks right to me.
  @goodtimeslim