df_to_xts: Create an xts object from a common data-frame format.

Description Usage Arguments Details Examples

Description

Time-series objects can be confusing for the R date/time beginner. This is one way to create an xts object – class extensible time series (from the zoo package) – from a data frame containing one column of dates and the rest data.

Usage

1
df_to_xts(mydf)

Arguments

mydf

A data frame with the first column containg dates, rest of columns containing data you want. Date column must be in yyyy-mm-dd format, either as character or Date objects.

Details

The resulting xts object can be easily graphed using dygraphs::dygraph(myxtsobject)

Examples

1
2
3
4
5
6
7
month = c("2014-01-01", "2014-02-01", "2014-03-01", "2014-04-01", "2014-05-01", "2014-06-01", "2014-07-01", "2014-08-01", "2014-09-01", "2014-10-01", "2014-11-01", "2014-12-01")
rate = c(6.6, 6.7, 6.6, 6.2, 6.3, 6.1, 6.2, 6.1, 5.9, 5.7, 5.8, 5.6)
unemp <- data.frame(month, rate, stringsAsFactors = FALSE )

unemp.xts <- df_to_xts(unemp)
# With dygraphs library installed, can then graph this with
# dygraphs::dygraph(unemp.xts)

smach/rvisutils documentation built on May 30, 2019, 3:06 a.m.