dcomtois / summarytools

R Package to Quickly and Neatly Summarize Data
522 stars 78 forks source link

Inhomogeneous behaviour using stby #160

Open sariogonfer opened 2 years ago

sariogonfer commented 2 years ago

Hi,

I am trying to use the function stby with the func descr to be applied. If I test stby in a notebook importing the library:

library(summarytools)
stby(caso$FCR, caso$cluster, descr, stats = "common", transpose = FALSE, style = "rmarkdown") 

The output tables are aggregated

  1 2 3
Mean 2.61 2.51 2.72
Std.Dev 0.14 0.13 0.13
Min 2.30 2.23 2.36
Median 2.60 2.50 2.70
Max 2.95 2.84 3.02
N.Valid 69.00 59.00 72.00
Pct.Valid 100.00 100.00 100.00

But if I try with:

summarytools::stby(caso$FCR, caso$cluster, descr, stats = "common", transpose = FALSE, style = "rmarkdown") 

The output is:

FCR by cluster

Data Frame: caso
N: 69

  1 2 3
Mean 2.61 2.51 2.72
Std.Dev 0.14 0.13 0.13
Min 2.30 2.23 2.36
Median 2.60 2.50 2.70
Max 2.95 2.84 3.02
N.Valid 69.00 59.00 72.00
Pct.Valid 100.00 100.00 100.00

Descriptive Statistics

value

N: 69

  value
Mean 2.61
Std.Dev 0.14
Min 2.30
Median 2.60
Max 2.95
N.Valid 69.00
Pct.Valid 100.00

N: 59

  value
Mean 2.51
Std.Dev 0.13
Min 2.23
Median 2.50
Max 2.84
N.Valid 59.00
Pct.Valid 100.00

N: 72

  value
Mean 2.72
Std.Dev 0.13
Min 2.36
Median 2.70
Max 3.02
N.Valid 72.00
Pct.Valid 100.00

The problem is that whether I want to use this function in a shiny app, and get the firt style, it always returns the second one. What is the difference betweem each other? How can I obligate the function to return the aggregate style?

dcomtois commented 2 years ago

Hmmm that's a tricky one... I'm a bit confused about the output, could you provide a small reproducible example pls? Shiny experts are most welcome to chip in, too. Thx.