I need to create one variable containing all 0/1 responses (and its version without blanks) which could be used in further analysis, tabulations etc. What is required is Pct.ofCases which is usually higher than 100%. Multiresponse sets are very common in market research as every question when you select more than one response is treated as multiresponse set. Some of these questions contain more than 30 variables so it's important to find a way in R which is relatively simple in SPSS or other stats tools.
One of examples of required tables is this SPSS table prepared in a couple of minutes:
I also have an issue with that. When I export my two data frames to excel, category names get missing and I can only see Freq, Pct.of.Resp and Pct.of.Cases in exported files.
Creating dataframes was a temporary solution but the main request (multiresponse variable) still remains unresolved...
perhaps I could do analysis by generating this type of tables:
library(plyr)
idea <- response.data %>%
group_by(Gender) %>%
summarise(Blank = mean(Blank),
Oil = mean(Oil),
MOT = mean(MOT),
Rep = mean(Rep),
Other = mean(Other),
count = n())
idea
but maybe we could specify range of variables in the data frame rather than listing them one by one?
The code above requires a modification as I don't have expected results...
I'm not clear on exactly what output you're after, but some summarise_all() (or summarise_at() if you want to explicitly include rather than exclude variables) could be useful:
I think I did not clearly highlight what the main point is though.
In this small sample I have only five 0/1 variables but in many cases I have sets of 20+ variables which are part of multiresponse questions.
I need to find a way of creating a separate variable containing all of these 0/1 questions or data frames which could be easily exported to excel tables but without typing names of all of questions 20+ (5 in this sample file).
I couldn't find any responses about possible packages therefore my idea was creating data frames using range of variables.
Finally, I thought my "categories" and "no.blank.categories" are really basic so I was looking for clever solutions create them using some range statements (like [2:6]) to get counts and Pct.of.Cases.
Thank you very much for your help. I think I found a solution.
I can rename all variables related to a multiresponse question by adding it's prefix and selecting variables with this prefix:
Hi, I'm impressed with the solution but I've started applying that to my real data.
I have a problem with adding one more level to the group_by. Let's say I have one additional variable to add to your solution "Type" (A or B). How can I add it as the first level?