I have a framework with a Date column, which is in a date format:
df<- data.frame(date=c("1997-01-01", "1997-01-02", "1997-01-03", "1997-01-04", "1997-01-05", "1997-01-06" ,"1997-01-07" ,"1997-01-08","1998-01-12", "1998-01-13", "1998-01-14", "1998-01-15" ,"1998-01-16", "1998-01-17", "1998-01-18", "1998-01-19"))
And I need to create a column that changes the unique combination of year / month in the Date column to a continuous month variable. I have 20 years of data, and I will have months from 1-240.
So the example for df above will return:
output<- data.frame(date=c("1997-01-01", "1997-01-02", "1997-01-03", "1997-01-04", "1997-01-05", "1997-01-06" ,"1997-01-07" ,"1997-01-08","1998-01-12", "1998-01-13", "1998-01-14", "1998-01-15" ,"1998-01-16", "1998-01-17", "1998-01-18", "1998-01-19"), continuous_month=c("1", "1", "1", "1", "1", "1" ,"1" ,"1","13", "13", "13", "13" ,"13", "13", "13", "13"))
NOTE: 01/1997 will be the first month, and I skipped the months 02/1997 (2nd month) -12/1997 (12th month) in the sample data frame, so 01/1998 will be the 13th month in the series.