[Solved] How can I create a new column for month and year from datetime and logically compare date time in R [closed]


You could do this:

df <- data.frame(date=c("18MAY2013:00:00:00","19MAY2013:00:00:00"))
df$year <- format(as.Date(df$date,"%d%B%Y"),"%Y")
df$month <- format(as.Date(df$date,"%d%B%Y"),"%m")

                date year month
1 18MAY2013:00:00:00 2013    05
2 19MAY2013:00:00:00 2013    05

1

solved How can I create a new column for month and year from datetime and logically compare date time in R [closed]