Quantcast
Viewing all articles
Browse latest Browse all 57

Data table output looks very different than xts output

I'm having trouble viewing a data table in a tabular format. If I use the PCRA package and export a dataset as an xts object (see the minimal example below), the xts object resembles a table:

class(stocksDat)[1] "xts" "zoo"> head(stocksDat[, 1:3])                   AAN         ABM         ABT1993-01-31  0.28947368 -0.11250000 -0.089711931993-02-28 -0.04081633  0.14893617 -0.050000001993-03-31 -0.08510638  0.01234568 -0.014354071993-04-30 -0.04651163  0.03658536  0.089126211993-05-31  0.08829268 -0.08875740 -0.026905831993-06-30 -0.01123596 -0.10389610 -0.05529954

But if I export it as a data.table (second part of minimal example), I get a 3 column output:

> class(stocksDat2)[1] "data.table" "data.frame"> stocksDat2       TickerLast       Date      Return    1:        AAN 1993-01-31  0.28947368    2:        ABM 1993-01-31 -0.11250000    3:        ABT 1993-01-31 -0.08971193    4:       ADBE 1993-01-31  0.31999999    5:        ADI 1993-01-31  0.01538462   ---                                  81140:        WGO 2015-12-31 -0.1155555781141:        WHR 2015-12-31 -0.0962958981142:        WMT 2015-12-31  0.0501359581143:        WTS 2015-12-31 -0.1052062781144:        XOM 2015-12-31 -0.04543236

What should I be doing to get the data.table to print just like the xts object, with a column of dates followed by columns of returns for each of the tickers? Converting the data.table to a data. Frame does not help. Is the PCRA output incorrectly formatted?

Sincerely and with many thanks in advance

Thomas Philips

Minimal example:Install package PCRA from CRAN

library(PCRA)library(xts)stockItems <- c("Date","TickerLast","Return")# No need to specify begin and end dates if you want all# Get the data as an xts object (the default)stocksDat  <- selectCRSPandSPGMI("monthly",          stockItems   = stockItems,          factorItems  = NULL,          subsetType   = NULL,          subsetValues = NULL,          outputType   = "xts")names(stocksDat)dim(stocksDat)head(stocksDat[,1:3])range(index(stocksDat)) # To see begin and end dates# Now for a data.table outputstocksDat2  <- selectCRSPandSPGMI("monthly",                        stockItems   = stockItems,                        factorItems  = NULL,                        subsetType   = NULL,                        subsetValues = NULL,                        outputType   = "data.table")names(stocksDat2)class(stocksDat2)dim(stocksDat2)head(stocksDat2)

Viewing all articles
Browse latest Browse all 57

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>