1
votes

I am trying to convert a csv data.frame into an xts and keep getting the following error:

the file is a csv daily stock data downloaded from Yahoo Finance for "AAPL"

Here is what I did so far:

library(xts)
AAPLcsv <- read.csv(file="~/Desktop/AAPL.csv")

class(AAPLcsv)
#[1] "data.frame"

AAPL <- as.xts(AAPLcsv[, -1], order.by = as.Date(AAPLcsv$Date, "%m/%d/%Y"))

Error in xts(x, order.by = order.by, frequency = frequency, ...) : 'order.by' cannot contain 'NA', 'NaN', or 'Inf'Error in xts(x, order.by = order.by, frequency = frequency, ...) : 'order.by' cannot contain 'NA', 'NaN', or 'Inf'

Help??

1
Can you check the as.Date(AAPLcsv$Date, "%m/%d/%Y"). Please show few of 'Date' valuesakrun
2013-01-01 through 2018-12-31, all are in the same formatakay113

1 Answers

1
votes

The format used is wrong in the OP's post. It should be %Y-%m-%d which is the default format, so, the format argument is not really needed

library(xts)
xts(AAPLcsv[, -1], order.by = as.Date(AAPLcsv$Date))