summarytools icon indicating copy to clipboard operation
summarytools copied to clipboard

Group Index Does Not Print When Applying stby Through a Function on a List of Data Frames

Open greg-botwin opened this issue 8 months ago • 0 comments

Hi, I love the package. Huge thank you for your efforts in maintenance and improvements!

Issue: I am attempting to lapply through a large number of data frames and I am uncovering a minor annoyance. When calling stby through an apply function, the group index name fails to print. Any idea on how I can get the similar behavior as if I called 'stby' individually? Below is a minimal example.

library(summarytools)
test_list <- list(df1 = data.frame(Group = c("a", "b", "a"), Data = c(2,4,6)),
                  df2 = data.frame(Group = c("c", "d", "c"), Data = c(3,5, 7)))

test_function <- function(x){
  summary <- stby(data = x, 
                  INDICES   = x$Group, 
                  FUN       = dfSummary, 
                  stats     = "common", 
                  transpose = TRUE,
                  simplify = FALSE)
}

lapply(test_list, test_function)

Created on 2023-11-12 with reprex v2.0.2

Session info
sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.1252 
#> [2] LC_CTYPE=English_United States.1252   
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.29     withr_2.5.2       lifecycle_1.0.3   reprex_2.0.2     
#>  [5] evaluate_0.23     rlang_1.1.2       cli_3.6.1         rstudioapi_0.15.0
#>  [9] fs_1.5.2          rmarkdown_2.25    tools_4.0.2       glue_1.6.2       
#> [13] xfun_0.41         yaml_2.3.5        fastmap_1.1.0     compiler_4.0.2   
#> [17] htmltools_0.5.7   knitr_1.45

greg-botwin avatar Nov 12 '23 15:11 greg-botwin