Skip to content
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

Unexpected adorn_totals("col") #570

Closed
ocelhay opened this issue Mar 19, 2024 · 1 comment
Closed

Unexpected adorn_totals("col") #570

ocelhay opened this issue Mar 19, 2024 · 1 comment

Comments

@ocelhay
Copy link

ocelhay commented Mar 19, 2024

Why would janitor::adorn_totals("col") give a total that is different from sum(tbl$n)?

tbl <- structure(list(address_cat = structure(1:10, levels = c("[0,10]", 
"(10,20]", "(20,30]", "(30,40]", "(40,50]", "(50,60]", "(60,70]", 
"(70,80]", "(80,90]", "(90,100]"), class = "factor"), n = c(313L, 
138L, 130L, 180L, 192L, 323L, 484L, 717L, 938L, 8463L)), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))


tbl
# A tibble: 10 × 2
   address_cat     n
   <fct>       <int>
 1 [0,10]        313
 2 (10,20]       138
 3 (20,30]       130
 4 (30,40]       180
 5 (40,50]       192
 6 (50,60]       323
 7 (60,70]       484
 8 (70,80]       717
 9 (80,90]       938
10 (90,100]     8463

sum(tbl$n)
# [1] 11878

tbl |> tidyr::pivot_wider(names_from = "address_cat", values_from = "n") |> janitor::adorn_totals("col")
 [0,10] (10,20] (20,30] (30,40] (40,50] (50,60] (60,70] (70,80] (80,90] (90,100] Total
    313     138     130     180     192     323     484     717     938     8463 11565
@ocelhay
Copy link
Author

ocelhay commented Mar 19, 2024

First column was excluded as indicated by the help.

@ocelhay ocelhay closed this as completed Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant