read.zoo is not returning needed date format

65 Views Asked by At

My initial data is in %y-%m-%d format...

using the code

returnsgamma <- read.zoo(returns, header = TRUE, sep = ",", FUN = as.chron)

the zoo file is returning values in the order %m/%d/%y

is there anyway to read.zoo and have the order of dates stay as %y/%m/%d or %d/%m/%y?

1

There are 1 best solutions below

0
On

Assuming the input shown in the Note at the end we can use the default Date class whose output when rendering defaults to yyyy-mm-dd or use chron with chron(..., out.format="y-m-d") which produces yy-mm-dd.

library(zoo)

read.csv.zoo(text = Lines, format = "%y-%m-%d")
## 2022-12-01 
##         34 

library(chron)
toChron <- function(x) as.chron(x, out.format = "y-m-d")
read.csv.zoo(text = Lines, FUN = toChron)
## 22-12-01 
##       34 

Note

Lines <- "date,value
22-12-01,34"