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

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

  •  30-06-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

y <- data.frame(
    date=format(index(x), '%Y-%m-%d'),
    time=format(index(x), '%H:%M:%S'),
    x=as.numeric(x)
)
write.csv(y, ...)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top