I have a Dataset with satisfaction scores (0-5) from airline passengers regarding multiple categories like cleanliness, seat comfort, gate location, etc.. The dataset also includes info about class, type of travel, age, and so on.
I want to find out wether business class travelers are more satisfied in every single category than economy class travelers.
So, the desired output would/could (depending on what's possible) be somewhere along the lines of:
| Category | Class | Mean score |
| ------------ | --------- | ---------- |
| Cleanliness | Business | 4.0 |
| Gate Location| Business | 4.0 |
Here, Business Class had the highest average satisfaction score out of all classes in the Categories Cleanliness and Gate location, which is why it's the one that gets depicted in the table. The score is interesting to see, but without it would also be fine.
I know that I can just check for the mean satisfaction scores of each category, grouped by class. (see below with example category cleanliness)
library(dplyr)
final_dataset %>%
group_by(Class) %>%
summarise_at(vars(Cleanliness), list(mean = mean))
That way I will know what the mean for the different classes is for a given category. I've tried that and it works. This is a lot of effort though and doesn't really look great. There has to be a better way so I can see a list of categories and which class is most satisfied, right?
Class is a factor (find the code below), while the satisfaction scores are doubles.
final_dataset$Class <- as.factor(final_dataset$Class)
I've tried this (but it didn't work. Don't even exactly know, what it does):
library( data.table )
setDT( final_dataset )
final_dataset[ , .( mean.change = mean( "Cleanliness" ) ),
by = Class
][ , Class[ which.max( mean.change ) ] ]
The error message reads:
Error in
[.data.table(final_dataset, , .(mean.change = mean("Cleanliness")), : fastmean was passed type character, not numeric or logical>
I read something about providing sample data in other posts while looking for solutions but have no clue if this is how to do it. I tried to insert a little bit as a sample. Just for reference: this is where I gut the dataset.
ID Class Check-in Service Online Boarding Gate Location Cleanliness
<chr> <dbl> <dbl>
1 Business 3 3 4 3
2 Economy Plus 2 2 3 5
3 Economy 2 2 3 2
4 Business 4 4 4 5
5 Economy 1 1 3 2
I hope that is all you need to understand my question, I'm fairly new to this.
Thanks in advance for your help!