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

Error with fct_na_value_to_level() and total="row" #94

Open
DanChaltiel opened this issue Jan 29, 2025 · 0 comments
Open

Error with fct_na_value_to_level() and total="row" #94

DanChaltiel opened this issue Jan 29, 2025 · 0 comments
Labels
bug 🐞 Something isn't working
Milestone

Comments

@DanChaltiel
Copy link
Owner

library(tidyverse)
library(crosstable)

df = tibble(x = sample(c("a", "b", NA), 50, replace=TRUE),
       y = sample(c("a", "b"), 50, replace=TRUE)) %>% 
  mutate(x=fct_na_value_to_level(x, "NA"))

df %>% crosstable(x, by=y)
#> # A tibble: 3 × 5
#>   .id   label variable a           b          
#>   <chr> <chr> <chr>    <chr>       <chr>      
#> 1 x     x     a        10 (50.00%) 10 (50.00%)
#> 2 x     x     b        9 (64.29%)  5 (35.71%) 
#> 3 x     x     NA       9 (56.25%)  7 (43.75%)

df %>% crosstable(x, by=y, total="row")
#> Error in `map2()`:
#> ℹ In index: 1.
#> ℹ With name: x.
#> Caused by error in `mutate()`:
#> ℹ In argument: `Total = .total`.
#> Caused by error:
#> ! `Total` must be size 3 or 1, not 4.

Created on 2025-01-29 with reprex v2.1.1

@DanChaltiel DanChaltiel added the bug 🐞 Something isn't working label Jan 29, 2025
@DanChaltiel DanChaltiel added this to the v0.9.0 milestone Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant