Skip to content

Spreading + removing irrelevant columns #572

@jackdolgin

Description

@jackdolgin

Such a big fan of tidyr! (I hope I'm doing this right, I've only posted to stackoverflow)

CO2low <- CO2 %>% filter(conc < 250)

spread(CO2low, conc, uptake) #attempt1

#    Plant        Type  Treatment   95  175
# 1    Qn1      Quebec nonchilled 16.0 30.4
# 2    Qn2      Quebec nonchilled 13.6 27.3
# 3    Qn3      Quebec nonchilled 16.2 32.4

CO2low$randoms <- runif(nrow(CO2low), min=0, max=1)
spread(CO2low, conc, uptake) #attempt2
#   Plant        Type  Treatment      randoms   95  175
# 1    Qn1      Quebec nonchilled 1.539457e-01 16.0   NA
# 2    Qn1      Quebec nonchilled 5.429544e-01   NA 30.4
# 3    Qn2      Quebec nonchilled 1.415618e-01 13.6   NA
# 4    Qn2      Quebec nonchilled 8.917103e-01   NA 27.3

I'd like my second spread attempt to result in the same output as the first spread attempt, and though I imagine I could use 'select(-randoms)', is there an argument in spread that would say something along the lines of, 'Remove any other columns whose values aren't identical between the rows we'd spread over'?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementpivoting ♻️pivot rectangular data to different "shapes"

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions