Hello Experts,
I am learning R. In one of the online learning courses, I came across the following exercise that I solved, however, Katacoda web platform says the result is NOT correct. I wanted to double-check if I am missing something. Problem:
Consider a data frame strDates having values 01/05/1965, 08/16/1975. Convert this to different date formats like month/date/year, year-month-date.
My Code:
dts <- c("01/05/1965", "08/16/1975")
strDates <- data.frame (dts)
dts1 <- format (as.Date(strDates$dts, format="%m/%d/%Y"), "%m/%d/%Y")
dts2 <- format (as.Date(strDates$dts, format="%m/%d/%Y"), "%Y-%m-%d")
strDates <- data.frame (dts1)
strDates
strDates <- data.frame (dts2)
strDates
Online Course: FrecoPlay (TCS) Lesson: Data Cleansing Using R, Platform: Katacoda
Seems fine to me. The web platform might be overly opinionated....
Also I like technocrats suggestion of using lubridate. It's a great package that makes a lot of date related work easier.
I think lubridate is a really great package to work with date format. In my experience, it is always great idea to use consistent format such as yyyy-mm-dd. It will work well with SQL and CSV data as well