Skip to content

Add adorn_totals as level in existing factor variable  #494

@themichjam

Description

@themichjam

Is there a way of adding the total called via adorn_totals as a new level to an existing factor? E.G. Adding the Total row produced by adorn_totals() as a factor level to the starwars sex variable?

Repex below:

# starwars data
data(starwars)

# gender 
starwars %>%
  count(sex)

# A tibble: 5 × 2
  sex                n
  <chr>          <int>
1 female            16
2 hermaphroditic     1
3 male              60
4 none               6
5 NA                 4

# make fct
starwars$sex <- as.factor(as.character(starwars$sex))

# with totals
starwars %>%
  count(sex) %>%
  adorn_totals()

            sex  n
         female 16
 hermaphroditic  1
           male 60
           none  6
           <NA>  4
          Total 87

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions