Re: [R] dplyr summarize by groups

2024-11-30 Thread Rui Barradas

Às 05:52 de 23/11/2024, tgs77m--- via R-help escreveu:

# Get mean, min, max sigma and skew by group

  options (digits = 3)
  library (ISwR
data(energy)

data %>%
   group_by(stature) %>%
   summarize(
 Mean = mean(expend),
 Min =  min(expend),
 Max = max(expend),
 Sigma = sd(expend),
 Skew = skew(expend))

# Output

   stature  Mean   Min   Max Sigma  Skew
  
1 lean 8.07  6.13  10.9  1.24 0.907
2 obese   10.3   8.79  12.8  1.40 0.587

Why does output stats vary in decimal places even when options (digits=3)
were set?

All the best

Thomas S.




[[alternative HTML version deleted]]

__
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Hello,


"Why does output stats vary in decimal places even when options 
(digits=3) were set?"


Yes, they do but shouldn't they? I'm seeing all numbers with 3 digits. 
Display digits and rounding are not the same thing.


Also, you don't need to load the package to have access to one of its 
data sets,



data(energy, package = "ISwR")


will load it. In this case, it's probably even better, "energy" is not 
an uncommon source for data and there might be data sets with the same 
name in other packages.



Hope this helps,

Rui Barradas




--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.com

__
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dplyr summarize by groups

2024-11-23 Thread Eric Berger
This is because options(digits=3) specifies the number of significant
digits, not the number of decimal places.
See ?options and search for digits.

> a <- 12.345
> options(digits=4)
> print(a)
[1] 12.35
> options(digits=5)
> print(a)
[1] 12.345
> options(digits=2)
> print(a)
[1] 12
>

On Sat, Nov 23, 2024 at 7:53 AM tgs77m--- via R-help 
wrote:

> # Get mean, min, max sigma and skew by group
>
>  options (digits = 3)
>  library (ISwR
> data(energy)
>
> data %>%
>   group_by(stature) %>%
>   summarize(
> Mean = mean(expend),
> Min =  min(expend),
> Max = max(expend),
> Sigma = sd(expend),
> Skew = skew(expend))
>
> # Output
>
>   stature  Mean   Min   Max Sigma  Skew
>  
> 1 lean 8.07  6.13  10.9  1.24 0.907
> 2 obese   10.3   8.79  12.8  1.40 0.587
>
> Why does output stats vary in decimal places even when options (digits=3)
> were set?
>
> All the best
>
> Thomas S.
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> [email protected] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.