Reputation: 1
I have a survey in which we have some questions where you tick the answers, as in the following image
The dataset looks like this Data
I need to turn the answers in my data set into categorical variables, such as this one:
ID | Choice | Choice_Cat |
---|---|---|
1 | Sun/Solar Photovoltaic, Wind Power | 1, 2 |
2 | Wind Power, Hydel | 2, 3 |
Anyone knows how to do this? Thanks in advance
at first I tried this command
data <- structure(list(CIQ_RES_choice = c("Sun/Solar Photovoltaic", "Wind Power",
"Hydel", "Biomass", "Geothermal", "Food crops", "I do not know Renewable Energy Sources")),
class ="data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7"))
as.data.frame(apply(data,1,function(x) {x<-as.numeric(factor(x,levels = unique(x)))}))
But I get a vector with 7 values such as this one
ID | Choice |
---|---|
1 | Sun/Solar Photovoltaic |
2 | Wind Power |
3 | Hydel |
Upvotes: 0
Views: 45