I have a date variable in a data frame with date in "YYYY-MM-DD" format.
I used the separate function(below) in tidyr
package which worked but it does not add columns to the table.
separate(<table name>, "<date variable>", c("Year", "Month", "Day"), sep = "-")
How can I get "Year", "Month" & "Day" variables added to the end of the table?
You need to define
argument to separate
.
See this example:
d <- data.frame(date = c("2017-02-23", "2017-02-22"))
separate(d, "date", c("Year", "Month", "Day"), sep = "-")
Which yields:
Year Month Day
1 2017 02 23
2 2017 02 22
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With