Skip to content

fct_reorder2() drops values #348

@hadley

Description

@hadley
library(forcats)
library(dplyr, warn.conflicts = FALSE)

by_age <- gss_cat |>
  count(age, marital) |>
  group_by(age) |>
  mutate(
    prop = n / sum(n)
  )

nrow(by_age)
#> [1] 357
with(by_age, length(fct_reorder2(marital, age, prop, .na_rm = TRUE)))
#> [1] 351
with(by_age, length(fct_reorder2(marital, age, prop)))
#> Warning: `fct_reorder2()` removing 6 missing values.
#> ℹ Use `.na_rm = TRUE` to silence this message.
#> ℹ Use `.na_rm = FALSE` to preserve NAs.
#> [1] 351

Created on 2023-02-27 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions