import_types <- tibble(
ColumnName = names(survey_default),
GuessedByReadr = map_chr(survey_default, ~ class(.x)[1]),
AfterManualParsing = map_chr(data, ~ class(.x)[1])
) %>%
mutate(Changed = if_else(GuessedByReadr != AfterManualParsing, "Yes", ""))
datatable(import_types, rownames = FALSE, options = list(dom = "t", pageLength = 27))## [1] "Number of rows: 90"
## [1] "Number of columns: 27"
# Helper function to extract top 3 most frequent values separated by " | "
get_top_values <- function(x) {
x_clean <- na.omit(as.character(x))
if (length(x_clean) == 0) return("")
top3 <- names(sort(table(x_clean), decreasing = TRUE))[1:min(3, length(unique(x_clean)))]
paste(top3, collapse = " | ")
}
# Build column-by-column summary dataframe
overview_df <- tibble(
ColumnName = names(data),
DataType = map_chr(data, ~ class(.x)[1]),
UniqueValues = map_int(data, ~ n_distinct(.x, na.rm = TRUE)),
PercentUnique = round(UniqueValues / nrow(data) * 100, 2),
MissingValues = map_int(data, ~ sum(is.na(.x))),
PercentMissing = round(MissingValues / nrow(data) * 100, 2),
ZeroValues = map_int(data, ~ if (is.numeric(.x)) sum(.x == 0, na.rm = TRUE) else NA_integer_),
PercentZero = round(ZeroValues / nrow(data) * 100, 2),
TopValues = map_chr(data, get_top_values)
)
datatable(
overview_df,
rownames = FALSE,
options = list(
dom = "t",
pageLength = 27,
scrollX = TRUE
)
)# Select all 6 numerical satisfaction variables
num_vars <- c(
"SatQueueing", "SatFoodPickup", "SatSeating",
"SatCleanliness", "SatTotalTime", "SatOverall"
)
# Helper function to compute statistical Mode
get_mode <- function(x) {
x_clean <- na.omit(x)
ux <- unique(x_clean)
ux[which.max(tabulate(match(x_clean, ux)))]
}
# Build comprehensive summary statistics table
summary_num_df <- map_dfr(num_vars, function(var_name) {
x <- data[[var_name]]
q1_val <- as.numeric(quantile(x, 0.25, na.rm = TRUE))
q3_val <- as.numeric(quantile(x, 0.75, na.rm = TRUE))
min_val <- min(x, na.rm = TRUE)
max_val <- max(x, na.rm = TRUE)
tibble(
Variable = var_name,
Mean = round(mean(x, na.rm = TRUE), 2),
Median = round(median(x, na.rm = TRUE), 2),
Mode = get_mode(x),
Min = min_val,
Q1 = round(q1_val, 2),
Q3 = round(q3_val, 2),
Max = max_val,
Range = max_val - min_val,
IQR = round(q3_val - q1_val, 2),
Variance = round(var(x, na.rm = TRUE), 2)
)
})
datatable(
summary_num_df,
rownames = FALSE,
options = list(dom = "t", scrollX = TRUE)
)# Compute IQR outlier limits and counts for each numerical variable
outliers_df <- map_dfr(num_vars, function(var_name) {
x <- na.omit(data[[var_name]])
q1 <- as.numeric(quantile(x, 0.25))
q3 <- as.numeric(quantile(x, 0.75))
iqr_val <- q3 - q1
lower <- q1 - 1.5 * iqr_val
upper <- q3 + 1.5 * iqr_val
tibble(
Variable = var_name,
LowerLimit = round(lower, 2),
UpperLimit = round(upper, 2),
BelowLower = sum(x < lower),
AboveUpper = sum(x > upper)
)
})
datatable(
outliers_df,
rownames = FALSE,
options = list(dom = "t")
)# Reshape numerical variables to long format for side-by-side interactive boxplot
sat_long <- data %>%
select(all_of(num_vars)) %>%
pivot_longer(cols = everything(), names_to = "Variable", values_to = "Score") %>%
filter(!is.na(Score))
hcboxplot(
x = sat_long$Score,
var = sat_long$Variable,
outliers = TRUE
) %>%
hc_chart(type = "column", zoomType = "xy") %>%
hc_yAxis(title = list(text = "Satisfaction Score"))time_fullness_tbl <- data %>%
filter(!is.na(VisitTime), !is.na(FullnessLevel)) %>%
count(VisitTime, FullnessLevel, name = "Responses") %>%
group_by(VisitTime) %>%
mutate(RowPercent = round(Responses / sum(Responses) * 100, 2)) %>%
ungroup()
datatable(
time_fullness_tbl,
rownames = FALSE,
options = list(dom = "tp", pageLength = 10, scrollX = TRUE)
)hchart(
time_fullness_tbl,
type = "column",
hcaes(x = VisitTime, y = RowPercent, group = FullnessLevel)
) %>%
hc_plotOptions(column = list(stacking = "percent")) %>%
hc_yAxis(title = list(text = "Percentage of Responses (%)")) %>%
hc_xAxis(title = list(text = "Visit Time Window")) %>%
hc_chart(zoomType = "xy")queue_sat_summary <- data %>%
filter(!is.na(QueueTime), !is.na(SatQueueing)) %>%
group_by(QueueTime) %>%
summarise(
Responses = n(),
SatMean = round(mean(SatQueueing), 2),
SatMedian = median(SatQueueing),
SatQ1 = as.numeric(quantile(SatQueueing, 0.25)),
SatQ3 = as.numeric(quantile(SatQueueing, 0.75)),
SatMin = min(SatQueueing),
SatMax = max(SatQueueing),
.groups = "drop"
)
datatable(
queue_sat_summary,
rownames = FALSE,
options = list(dom = "t", scrollX = TRUE)
)queue_sat_clean <- data %>%
filter(!is.na(QueueTime), !is.na(SatQueueing))
hcboxplot(
x = queue_sat_clean$SatQueueing,
var = queue_sat_clean$QueueTime,
outliers = TRUE
) %>%
hc_chart(type = "column", zoomType = "xy") %>%
hc_xAxis(title = list(text = "Queueing Time Bracket")) %>%
hc_yAxis(title = list(text = "Queueing Satisfaction Score (1–5)"))iu_alt_tbl <- data %>%
filter(!is.na(IUStudent), !is.na(OvercrowdAlternative)) %>%
count(IUStudent, OvercrowdAlternative, name = "Responses") %>%
group_by(IUStudent) %>%
mutate(GroupPercent = round(Responses / sum(Responses) * 100, 2)) %>%
ungroup()
datatable(
iu_alt_tbl,
rownames = FALSE,
options = list(dom = "t", scrollX = TRUE)
)time_overall_summary <- data %>%
filter(!is.na(SatTotalTime), !is.na(SatOverall)) %>%
group_by(SatTotalTime) %>%
summarise(
Responses = n(),
OverallMedian = median(SatOverall),
OverallQ1 = as.numeric(quantile(SatOverall, 0.25)),
OverallQ3 = as.numeric(quantile(SatOverall, 0.75)),
OverallMin = min(SatOverall),
OverallMax = max(SatOverall),
.groups = "drop"
)
datatable(
time_overall_summary,
rownames = FALSE,
options = list(dom = "t")
)time_overall_clean <- data %>%
filter(!is.na(SatTotalTime), !is.na(SatOverall)) %>%
mutate(SatTotalTime = factor(SatTotalTime, levels = 1:5))
hcboxplot(
x = time_overall_clean$SatOverall,
var = time_overall_clean$SatTotalTime,
outliers = TRUE
) %>%
hc_chart(type = "column", zoomType = "xy") %>%
hc_xAxis(title = list(text = "Satisfaction with Total Time Spent (1–5)")) %>%
hc_yAxis(title = list(text = "Overall Canteen Satisfaction (1–5)"))