I working with monthly data. Data is in a specific format in two columns Month and Year. Below you can see a sample of data:
df<-data.frame(
Month=c("m1","m2","m3","m4","m5","m6","m7","m8","m9","m10","m11","m12"),
Year=c("2020","2020","2020","2020","2020","2020","2020","2020","2020","2020","2020","2020"))
Now I want to convert this data, from that format into the format shown below or more precisely in column Date
So can anybody help me how to solve this problem?
>Solution :
In base R you can do:
df$Date <- as.Date(paste0(df$Year, gsub("m", "-", df$Month, fixed = TRUE), "-01"))
