Skip to content

Feature request: have pivot_wider put column in factor level order #1611

@billdenney

Description

@billdenney

This is related to but distinct from #839.

Would it be a feature of interest for pivot_wider to put columns in factor level order rather than what appears to be first-seen order?

In the example below, I'd prefer to see column "B" before column "A".

library(tidyr)

d <- data.frame(x = factor(c("A", "B"), levels = c("B", "A")), y = 1:2)
pivot_wider(d, names_from = "x", values_from = "y")
#> # A tibble: 1 × 2
#>       A     B
#>   <int> <int>
#> 1     1     2

Created on 2025-08-28 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions