Version: | 1.0.4 |
Date: | 2021-01-09 |
Type: | Package |
Title: | Convert Tibbles or Data Frames to Xts Easily |
Description: | Facilitate the movement between data frames to 'xts'. Particularly useful when moving from 'tidyverse' to the widely used 'xts' package, which is the input format of choice to various other packages. It also allows the user to use a 'spread_by' argument for a character column 'xts' conversion. |
Maintainer: | Nico Katzke <nfkatzke@gmail.com> |
BugReports: | https://github.com/nicktz/tbl2xts/issues |
URL: | https://tbl2xts.nfkatzke.com |
Depends: | R (≥ 3.3.1) |
Imports: | xts, zoo, dplyr (≥ 0.8.0.0), tibble, rlang |
License: | GPL-3 |
LazyData: | TRUE |
RoxygenNote: | 7.1.1 |
Suggests: | knitr, rmarkdown, ggplot2, PerformanceAnalytics |
Repository: | CRAN |
NeedsCompilation: | yes |
ByteCompile: | yes |
VignetteBuilder: | knitr |
Packaged: | 2021-01-12 09:30:16 UTC; E695461 |
Author: | Nico Katzke [aut, cre] |
Date/Publication: | 2021-01-12 14:30:02 UTC |
This is a toy dataset, which is simply an example of a Total Return Index that can be used in packages requiring xts
Description
This is a toy dataset, which is simply an example of a Total Return Index that can be used in packages requiring xts
Usage
TRI
Format
A data frame with 16590 rows and 3 variables:
- Date
Valid date column
- Country
Country, by which to spread
- TRI
Total Returns
- Return
Simple Returns
tbl_xts
Description
This function converts data from a tbl_df() format into a xts format. Note that the dataframe must be a data.frame or tbl_df, and either the first column must be a valid date column, or there must be one column named date, Date or DATE to order by. tbl_xts also allows the user to specify the columns to be transformed to xts, as well as an option for spreading by a single character or factor type column. See the example for details.
Usage
tbl_xts(
tblData,
cols_to_xts,
spread_by,
spread_name_pos,
Colnames_Exact = FALSE
)
Arguments
tblData |
A tbl_df type dataframe |
cols_to_xts |
Specify the columns to be converted to xts format. If not provided, it will by default transform all numeric columns to xts. |
spread_by |
A character or factor type column used to create xts series by. See example. |
spread_name_pos |
Add the column name of the column used to spread_by as a Suffix, Prefix or None. Defaults to Suffix (puts spread_by name at end of column name, separated by an underscore). |
Colnames_Exact |
Stops xts natively replacing spaces in column names with full stops. Kept FALSE as default, as most users expect this behavior. |
Value
A xts dataframe, with columns xts series ordered by the first (date) column.
Examples
## Not run:
library(dplyr)
library(tbl2xts)
data(TRI)
tbl_xts(tbl2xts::TRI, cols_to_xts = TRI, spread_by = Country)
# tbl - xts - tbl:
tbl_xts(tbl2xts::TRI, cols_to_xts = TRI, spread_by = Country) %>% xts_tbl()
## End(Not run)
xts_tbl
Description
This function converts data from a xts object to a tbl_df(). Note that the dataframe must be of type xts and ordered by a date column. This date column will be preserved and save as "date".
Usage
xts_tbl(xts, Colnames_Exact = FALSE)
Arguments
xts |
A xts series that will be converted to a tbl_df(). |
Colnames_Exact |
Stops xts natively replacing spaces in column names with full stops. Kept FALSE as default, as most users expect this behavior. |
Value
A tbl_df() with the first column the "date" column used to order the xts series by.
Examples
## Not run:
library(dplyr)
data(TRI)
df_xts_tbl <- TRI %>% tbl_xts(., cols_to_xts = TRI, spread_by = Country) %>% xts_tbl()
## End(Not run)