I have date and time in one column of the form 2004/12/15 9:30 , how can I format it to date, so that I can plot it on x axis. Also posxlt is not working for me.
1 Answer
$\begingroup$
$\endgroup$
as.POSIXct formats dates so as to include the time, while as.Date formats so as to include just the year, month, and date, i.e. yyyy-mm-dd.
Assuming you have a column x with the dates and times included as you mentioned, i.e. 2004/12/15 9:30, then you can simply apply:
date<-as.Date(x)
Now, you can check if it is in date format through using:
str(Date)
You should find that the times are no longer visible and only the dates are displayed.