Factorize date by month in R
I have a data frame with a column of dates. I am looking for an efficient way to divide these dates up by month to create a new column called "month". Each row with have a date, the full date, and a column just reporting the month (derived from date). Thanks! Here is example data.
dat <- data.frame(as.Date(c("2017-06-21", "2017-07-05", "2017-08-19", "2017-09-25"), format = "%Y-%m-%d")) colnames(dat) <- "Date"
I suppose this is similar to How to extract Month from date in R but do I have to convert to as.POSIXlt? Can this be achieved with class = Date?