Write ZOO (XTS) object into CSV file by separating index column into two columns

StackOverflow https://stackoverflow.com/questions/22945902

  •  30-06-2023
  •  | 
  •  

Pergunta

I have 2-column (index and value) ZOO object, where index contains date and time values:

2010-02-18 13:11:00 48.090 
2010-02-18 13:12:00 48.110 
2010-02-18 13:13:00 48.100

I want to save this ZOO object into CSV by separating index column into two independent columns - date column, and time column:

2010-02-18,13:11:00,48.090 
2010-02-18,13:12:00,48.110 
2010-02-18,13:13:00,48.100

How I can do this?

Foi útil?

Solução

y <- data.frame(
    date=format(index(x), '%Y-%m-%d'),
    time=format(index(x), '%H:%M:%S'),
    x=as.numeric(x)
)
write.csv(y, ...)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top