I have a data drame with results for a survey with 1 column for each question. There are only 5 different satisfaction levels(VDSAT,DSAT,NTL,SAT,VSAT), so each column are a bunch of satisfaction levels.
I would like to have a summary data.frame that counts, for each column, how many different satisfaction levels did I get (put 0 if no occurrencies). Each column would be a question, each row a satisfaction level and the intersections the counts.
I have tried with apply(df,2,table)
which will give me a list of tables and then put into data.frame format with data.frame(matrix(unlist(table),nrow=5))
.
This approach works well if I have at least 1 result of each satisfaction level for every column. If one column, let's say, does not have "DSAT", then the resulting data.frame is not correct as the missing value is not recognized by the table command from the apply.
Basically the output would be like the following:
Q1 Q2 Q3 Q4 Q5 Satisfaction
12 16 22 24 23 Very dissatisfied
27 30 33 24 33 Dissatisfied
49 36 33 30 32 Neutral
6 11 17 25 22 Satisfied
22 23 11 13 6 Very satisfied
Thanks very much
Kind regards,
EDIT: Sample of raw data:
Q1 Q2 Q3 Q4 Q5
Very satisfied Very satisfied Very satisfied Very satisfied Very satisfied
Satisfied Dissatisfied Very dissatisfied Dissatisfied Satisfied
Very satisfied Very satisfied Very satisfied Very satisfied Very satisfied
Satisfied Satisfied Satisfied Satisfied Satisfied
Very satisfied Very satisfied Very satisfied Very satisfied Very satisfied
... ... ... ... ...