0
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Look at strptime $\endgroup$
    – HEITZ
    Oct 8, 2018 at 22:19

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.