R/prepare_ext_obs_table.R
prepare_ext_obs_table.Rd
Reads a data frame, sorts it by the given variable and displays the top and bottom n observations.
prepare_ext_obs_table( df, n = 5, cs_id = NULL, ts_id = NULL, var = utils::tail(colnames(df[sapply(df, is.numeric) & (!colnames(df) %in% c(cs_id, ts_id))]), n = 1), ... )
df | Data frame |
---|---|
n | The number of top/bottom observations that you want to report. |
cs_id | The variable(s) identifying the cross-section in the data. |
ts_id | The variable identifying the time-series in the data. |
var | Variable to display. Defaults to the last numerical variable of the data frame. |
... | Additional parameters that are passed to |
A list containing two items:
A data frame containing the top/bottom n observations
The return value provided by kable
containing the formatted table
When both cs_id
and ts_id
are omitted, all variables are tabulated.
Otherwise, var
is tabulated along with the identifiers.
Infinite values in var
are omitted.
The default parameters for calling kable
,
are format = "html", digits = 3, format.args = list(big.mark = ','), row.names = FALSE
.
t <- prepare_ext_obs_table(russell_3000, n = 10, cs_id = c("coid", "coname"), ts_id = "period", var = "sales") t$df#> coid coname period sales #> 8517 WMT Wal-Mart Stores, Inc. FY2015 485651.00 #> 8518 WMT Wal-Mart Stores, Inc. FY2016 482130.00 #> 8516 WMT Wal-Mart Stores, Inc. FY2014 476294.00 #> 8664 XOM Exxon Mobil Corporation FY2013 420836.00 #> 8665 XOM Exxon Mobil Corporation FY2014 394105.00 #> 8666 XOM Exxon Mobil Corporation FY2015 259488.00 #> 33 AAPL Apple Inc. FY2015 233715.00 #> 2092 CVX Chevron Corporation FY2013 220264.00 #> 8667 XOM Exxon Mobil Corporation FY2016 218608.00 #> 34 AAPL Apple Inc. FY2016 215639.00 #> 3938 IDRA Idera Pharmaceuticals, Inc. FY2014 0.07 #> 7386 STML Stemline Therapeutics, Inc. FY2013 0.07 #> 92 ACAD ACADIA Pharmaceuticals Inc. FY2015 0.06 #> 484 AMPE Ampio Pharmaceuticals, Inc. FY2013 0.05 #> 838 AXDX Accelerate Diagnostics, Inc. FY2013 0.05 #> 3937 IDRA Idera Pharmaceuticals, Inc. FY2013 0.05 #> 5471 NK NantKwest, Inc. FY2016 0.04 #> 6343 PRTK Paratek Pharmaceuticals, Inc. FY2016 0.03 #> 3343 GLYC GlycoMimetics, Inc. FY2016 0.02 #> 1157 BPTH Bio-Path Holdings, Inc. FY2016 0.01