Hannah
Hannah

Reputation: 1

Ordeing dates in R

When I order the days in R they appear correctly like this (NZ date formatted aa dd,mm,yyyy):

pHAuckOtehaStream$Date[164:175]
 [1] 7/01/00  1/02/00  7/03/00  4/04/00  2/05/00  8/06/00  4/07/00  31/07/00 5/09/00 
[10] 3/10/00  31/10/00 5/12/00

Which is correct, however when I plot these it is taking the dd as the order rather than the month or year the American form of dates, how can i change this? enter image description here

Upvotes: 0

Views: 33

Answers (1)

Weihuang Wong
Weihuang Wong

Reputation: 13128

An alternative to as.Date (as proposed in the comments) is the date parsing functions in the lubridate package, which parses dates stored in a character vector into a Date object.

library(lubridate)
dmy(c("7/01/00","1/02/00"))
# [1] "2000-01-07" "2000-02-01"

Upvotes: 1

Related Questions