rxts

error in xts - "'order.by' cannot contain 'NA', 'NaN', or 'Inf'"


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??


Solution

  • 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))