Skip to content

Distinct creates duplicate columns when groups are included in the distinct #2001

@ajongbloets

Description

@ajongbloets

When I use distinct on a grouped data.frame and explicitly put the group columns in the distinct, then I get duplicated columns:

df <- data.frame( a = c(1,2,3), b=c(4,5,6), c=c(7,8,9))

df %>% group_by(a) %>% distinct(a,b)
# creates a data.frame with two 'a' columns

Since putting 'a' in the distinct is not necessary as the group_by already makes sure that every value in 'a' is unique, this problem is easily fixed on the user side.

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