-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thousand separator (i.e ",") #43
Comments
Good idea! In the meantime, you could also use custom functions like this: library(tidyverse)
library(crosstable)
f = scales::label_dollar(accuracy=0.1, prefix="")
iris %>%
select(starts_with("Sepal")) %>%
mutate_all(~.x*10000) %>%
crosstable(funs=c(mean=\(x) f(mean(x)), sd=\(x) f(sd(x))))
#> # A tibble: 4 x 4
#> .id label variable value
#> <chr> <chr> <chr> <chr>
#> 1 Sepal.Length Sepal.Length mean 58,433.3
#> 2 Sepal.Length Sepal.Length sd 8,280.7
#> 3 Sepal.Width Sepal.Width mean 30,573.3
#> 4 Sepal.Width Sepal.Width sd 4,358.7 Created on 2023-07-21 with reprex v2.0.2 |
I just realized that it doesn't work for counting categorical variables: f = scales::label_dollar(accuracy=0.1, prefix="")
iris %>%
slice(rep(1:n(), each = 100)) %>%
select(Species) %>%
crosstable(funs=c(count=\(x) f(count(x))))
# A tibble: 3 × 4
.id label variable value
<chr> <chr> <chr> <chr>
1 Species Species setosa 5000 (33.33%)
2 Species Species versicolor 5000 (33.33%)
3 Species Species virginica 5000 (33.33%) |
iris %>%
slice(rep(1:n(), each = 100)) %>%
select(Species) %>%
crosstable(percent_pattern="N={n} (P={p_col})",
percent_digits=1)
# A tibble: 3 x 4
.id label variable value
<chr> <chr> <chr> <chr>
1 Species Species setosa N=5000 (P=33.3%)
2 Species Species versicolor N=5000 (P=33.3%)
3 Species Species virginica N=5000 (P=33.3%) |
Describe the new feature
Most of the time when I am dealing with number of the range of thousands, reducing that numbers with scientific notation is too much, so having a thousand separator would improve the readiness of that numbers.
Known workaround
I am just accepting as it is.
The text was updated successfully, but these errors were encountered: