Skip to content

Convert checkboxes from wide to long by specific variable(s) #70

@darthpathos76

Description

@darthpathos76

Hi -

I'd like to be able to do something like this:
Age Group | Ice Cream Flavour | Toppings___1 | Toppings___2 | Toppings___3 | Toppings___4
15-24 | Chocolate | Checked | Checkec | Checked | Unchecked

and convert it to
Age Group | Ice Cream Flavour | Toppings
15-24 | Chocolate | Sprinkles
15-24 | Chocolate | Peanuts
15-24 | Chocolate | Whipped Cream

I've done this using the code below (extremely inelegant but I'm a SQL guy and this worked):

geniden5 <- as.data.frame(sqldf("select hours, GenIdentity from geniden4 where GenIdentity<>'NA'"))
geniden6 <- bind_rows(geniden5,
sqldf("select hours, male as GenIdentity from geniden4 where male<>'NA'"),
sqldf("select hours, transwoman as GenIdentity from geniden4 where transwoman<>'NA'"),
sqldf("select hours, transman as GenIdentity from geniden4 where transman<>'NA'"),
sqldf("select hours, genderqueer as GenIdentity from geniden4 where genderqueer<>'NA'"),
sqldf("select hours, nonbinary as GenIdentity from geniden4 where nonbinary<>'NA'"),
sqldf("select hours, twospirit as GenIdentity from geniden4 where twospirit<>'NA'"),
sqldf("select hours, questioning as GenIdentity from geniden4 where questioning<>'NA'"),
sqldf("select hours, another as GenIdentity from geniden4 where another<>'NA'"),
sqldf("select hours, dontknow as GenIdentity from geniden4 where dontknow<>'NA'"),
sqldf("select hours, noanswer as GenIdentity from geniden4 where noanswer<>'NA'")
)

I'd love a "make_choose_long" option so that I could do something like
make_choose_long(data, age_group, icecream_flavour, by=toppings)

or something similar.
Thanks
Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions