Summaries and assignment

describe applies summary to each variable and aligns statistics by name. It retains a data.frame for one variable; with t = FALSE, variables become rows. Missing statistics are NA. Columns convert to numeric where possible; heterogeneous statistics remain text. Date and POSIXt summaries retain calendar precision.

flextable = TRUE requires flextable. ft_args customizes the table. Optional rendering is tested through structure and values rather than the printed text of a particular flextable version.

The %<...% and %...>% operators assign objects. Use a list with .envir to select the destination and .warn to control the global-environment warning. If every requested name occurs in the values, assignment matches by name; otherwise it matches by position and requires equal lengths. Duplicate targets, locked or active bindings, and invalid lengths are detected before writing any object.

For compatibility, plain target names without .envir select the global environment and warn. Examples use an explicit environment. The operators return NULL invisibly.

library(Dmisc)
describe(data.frame(value = c(1, 2, NA), group = factor(c("A", "B", "A"))))
##         value group
## Min.     1.00    NA
## 1st Qu.  1.25    NA
## Median   1.50    NA
## Mean     1.50    NA
## 3rd Qu.  1.75    NA
## Max.     2.00    NA
## NAs      1.00    NA
## A          NA     2
## B          NA     1
output <- new.env(parent = emptyenv())
list("first", "second", .envir = output, .warn = FALSE) %<...% list(second = 20, first = 10)
stopifnot(output$first == 10, output$second == 20)
as.list(output)
## $first
## [1] 10
## 
## $second
## [1] 20