Hi everyone,
I have a dataset and I have a column named "fashion.course" that looks like this on my data tab (for row one) for example: Fashion A catalogue plan Sewing up
When I call the variable/column "fashion.course" in R: is shows up as:
[1] "Fashion\nA catalogue plan\nSewing up"
[2] "Fashion\nA catalogue plan\nSewing up"
[3] "Fashion\nDrying material\nA catalogue plan\nTearing\nSewing up\nHemming\nDrying material to sew."
The column/variable "fashion.course" can have a different combinations as a result of respondents choosing for 14 answers(check all that apply question).
When I run R, I want each of the responses within the column to be placed in its respective new column as 1 or 0.I want all 14 answers to have its own column.
For example,I want it my data to look like this when it is done:
fashion.course Fashion A catalogue plan Sewing up Tearing......all 14 answers
Fashion A catalogue plan Sewing up 1 1 1 0
Would you be able to help me find the appropriate way to achieve something like this?
You can use grepl() to search for character strings and ifelse() to create binary variables
You need to write 14 lines of code: 1 for each new binary variable that you want
Yes replace "df" with the name of your data frame. And yes it will work with spaces. If you want to keep spaces in your column names use `` for example
df$`Drying material to sew `
Also you don't need to use the full name of the course with grepl(), any unique string of characters within the name will do, for example
df$`Drying material to sew` <- ifelse(grepl("Drying material", df$fashion.course),1,0)
as long as none of the other course names contain the phrase "Drying material". does that make sense?