0

This is my first question on Stackoverflow. I have recently started to use R programming. I have a dataset where month and year are in two columns.

Year     Month 
2019     January
2018     February
2019     April
2018     June

This is how my data look like. I want to combine these two columns and use it as a time series in R.

smci
  • 32,567
  • 20
  • 113
  • 146
  • You will need a day, but something like that: `your_df <- your_df %>% dplyr::mutate(Time = as.Date(paste(Year, Month, "1",sep="-"), "%Y-%B-%d"))` – MLavoie Jan 09 '20 at 14:55
  • Also see https://stackoverflow.com/q/30576495/5325862, https://stackoverflow.com/q/45471834/5325862, https://stackoverflow.com/q/39420136/5325862, https://stackoverflow.com/q/6242955/5325862, https://stackoverflow.com/q/26697399/5325862, https://stackoverflow.com/q/33572818/5325862, https://stackoverflow.com/q/41122645/5325862... there's more, but those should have you covered – camille Jan 09 '20 at 15:26
  • Thank you MLavoie. Resolved the issue the way I wanted it. – Ehsan Chowdhury Jan 10 '20 at 00:50

1 Answers1

0

See below code:

library(anytime)

Year = c(2019, 2018, 2019, 2018)
Month = c('January', 'February', 'April', 'June')
df = data.frame(Year, Month)
df$Date <- anydate(paste('01', df$Month, df$Year))

df

Output df

 Year   Month      Date
 2019  January 2019-01-01
 2018 February 2018-02-01
 2019    April 2019-04-01
 2018     June 2018-06-01
KApril
  • 632
  • 1
  • 8
  • 20