joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

Deleting time from the index of an xts object #370

Closed avrenli2 closed 2 years ago

avrenli2 commented 2 years ago

Description

When I run the following code, the index of the xts object includes both date and time of day.

Expected behavior

I would like the index of the xts object to only include the date; and not time of day.

Minimal, reproducible example

library(quantmod)
xts() -> HISTORY
c("SBUX","TSLA","CAKE") -> STOCKS
for (SYMBOL in STOCKS) {
  getSymbols(SYMBOL , from="2017-1-1" , to="2022-1-1" , auto.assign=F) -> PRICE
  monthlyReturn(PRICE[,6])  ->  RETURNS
  cbind(HISTORY,RETURNS) -> HISTORY
}

STOCKS -> colnames(HISTORY)
head(HISTORY)

Session Info

[Insert your sessionInfo() output]
joshuaulrich commented 2 years ago

The index has a time because you create HISTORY <- xts() and the default index for xts objects has a time. Set HISTORY <- NULL instead.