Combining year-month data to continuous month variable (lubridate)

Hello,

I've got the following dataset year-month variable going from 1995 to 1999 and months 1 to 12.

image

The months start at 1 again at each new year. I want to create a continous month variable from 1 to 60, i can't find the correce lubridate code for this, any suggestions?

Much appreciated,

Best regards, Joris

You don't need lubridate for this. Are they integers or character? If they're integers:

df <- data.frame(YEAR=rep(1995:1999, each=12),
				 MONTH=rep(1:12,1999-1995+1))

df$new_month <- (df$YEAR - min(df$YEAR)) * 12 + df$MONTH

If they're character just wrap them in as.numeric()

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.