Learn R Programming

tidyquant (version 0.3.0)

as_xts: Coerce objects to xts, designed to work with tibble and data.frame objects

Description

Coerce objects to xts, designed to work with tibble and data.frame objects

Usage

as_xts(x, date_col = NULL, ...)
as_xts_(x, date_col = NULL, ...)

Arguments

x
A data.frame (with date column), matrix, xts, zoo, timeSeries, etc object.
date_col
Required for objects that inherit the data.frame class. Must specify a date column that is of the date class. Unused for non-data.frame objects.
...
Additional parameters passed to xts::as.xts.

Value

Returns a xts object.

Details

as_xts is a wrapper for xts::as.xts that includes a date_col argument. When date_col is specified, the date column is used as row names during coercion to xts class. The date column must be in a date format (i.e. date class).

as_xts_ evaluates the date_col using Non-Standard Evaluation (NSE). See vignette("nse") for details.

It is possible to coerce non-data.frame-like objects including zoo, timeSeries, ts, and irts objects. There is no need to specify the date_col argument.

See Also

as_tibble

Examples

Run this code
# Load libraries
library(tidyverse)
library(tidyquant)

tq_get("AAPL", get = "stock.prices") %>%
    as_xts(date_col = date)

# Non-Standard Evaluation (NSE)
x <- "date"
tq_get("AAPL", get = "stock.prices") %>%
    as_xts_(date_col = x)

Run the code above in your browser using DataLab