1 Data import check

This table compares the data type that readr guessed for each column with the data type after we set the types ourselves. “Yes” in the last column means the type was changed.

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))

This table lists the values that R could not read in the expected format. An empty table means every value was read correctly.

datatable(prob_raw, rownames = FALSE, options = list(dom = "tp", pageLength = 5))

2 Data overview

This line shows the number of rows in the dataset. Each row is one survey response.

paste("Number of rows:", nrow(data))
## [1] "Number of rows: 90"

This line shows the number of columns, which is the number of survey questions (variables).

paste("Number of columns:", ncol(data))
## [1] "Number of columns: 27"

This table gives a quick summary of every column: its data type, the number of different values, missing values, zero values and the three most common values.

# 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
  )
)

This table shows the raw data so we can see what the responses look like.

datatable(
  data,
  rownames = FALSE,
  options = list(
    pageLength = 10,
    scrollX = TRUE
  )
)

3 Univariate analysis – categorical variables

3.1 Respondent Identifiers and Demographics

3.1.1 Student Name

This table counts how many times each student name appears. If every name appears once, each row is a different person.

student_name_tbl <- freq_table(data, StudentName)
datatable(student_name_tbl, rownames = FALSE, options = list(dom = "tp", pageLength = 10))

3.1.2 IU Student Status

This table shows whether the respondent is an IU student (Yes) or not (No), with the number and percentage of responses for each answer.

iu_student_tbl <- freq_table(data, IUStudent)
datatable(iu_student_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about whether the respondent is an IU student (Yes) or not (No) more easily.

hchart(iu_student_tbl, type = "column", hcaes(x = IUStudent, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.2 Visit Behavior and Purpose

3.2.1 VisitTime

This table shows the time of day when students usually go to the canteen, with the number and percentage of responses for each answer.

visit_time_tbl <- freq_table(data, VisitTime)
datatable(visit_time_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about the time of day when students usually go to the canteen more easily.

hchart(visit_time_tbl, type = "bar", hcaes(x = VisitTime, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.2.2 Visit Purpose

This table shows the main reason students use the canteen, with the number and percentage of responses for each answer.

visit_purpose_tbl <- freq_table(data, VisitPurpose)
datatable(visit_purpose_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about the main reason students use the canteen more easily.

hchart(visit_purpose_tbl, type = "bar", hcaes(x = VisitPurpose, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.2.3 Stay Reason

This table shows why students stay at the table after eating, with the number and percentage of responses for each answer.

stay_reason_tbl <- freq_table(data, StayReason)
datatable(stay_reason_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about why students stay at the table after eating more easily.

hchart(stay_reason_tbl, type = "bar", hcaes(x = StayReason, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.2.4 Overcrowd Alternative

This table shows what students usually do when the canteen is too crowded, with the number and percentage of responses for each answer.

alternative_tbl <- freq_table(data, OvercrowdAlternative)
datatable(alternative_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about what students usually do when the canteen is too crowded more easily.

hchart(alternative_tbl, type = "bar", hcaes(x = OvercrowdAlternative, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3 Capacity, Waiting Times, and Seating Conditions

3.3.1 Fullness Level

This table shows how full the canteen was when students arrived, with the number and percentage of responses for each answer.

fullness_tbl <- freq_table(data, FullnessLevel, sort_desc = FALSE)
datatable(fullness_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how full the canteen was when students arrived more easily.

hchart(fullness_tbl, type = "bar", hcaes(x = FullnessLevel, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.2 Queue Time

This table shows how long students wait in line to order and pay, with the number and percentage of responses for each answer.

queue_time_tbl <- freq_table(data, QueueTime, sort_desc = FALSE)
datatable(queue_time_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how long students wait in line to order and pay more easily.

hchart(queue_time_tbl, type = "column", hcaes(x = QueueTime, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.3 Food Wait Time

This table shows how long students wait to get their food after paying, with the number and percentage of responses for each answer.

food_wait_tbl <- freq_table(data, FoodWaitTime, sort_desc = FALSE)
datatable(food_wait_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how long students wait to get their food after paying more easily.

hchart(food_wait_tbl, type = "column", hcaes(x = FoodWaitTime, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.4 Seat Find Time

This table shows how long it takes students to find a seat, with the number and percentage of responses for each answer.

seat_find_tbl <- freq_table(data, SeatFindTime)
datatable(seat_find_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how long it takes students to find a seat more easily.

hchart(seat_find_tbl, type = "bar", hcaes(x = SeatFindTime, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.5 Table Finding Difficulty

This table shows how hard it is to find a table for a group at peak hours, with the number and percentage of responses for each answer.

table_diff_tbl <- freq_table(data, TableDifficulty, sort_desc = FALSE)
datatable(table_diff_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how hard it is to find a table for a group at peak hours more easily.

hchart(table_diff_tbl, type = "bar", hcaes(x = TableDifficulty, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.6 Table Cleanliness

This table shows how clean the tables are when students sit down, with the number and percentage of responses for each answer.

cleanliness_tbl <- freq_table(data, TableCleanliness)
datatable(cleanliness_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how clean the tables are when students sit down more easily.

hchart(cleanliness_tbl, type = "bar", hcaes(x = TableCleanliness, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.7 Sold Out Freq

This table shows how often a food item is sold out when students order, with the number and percentage of responses for each answer.

soldout_tbl <- freq_table(data, SoldOutFreq, sort_desc = FALSE)
datatable(soldout_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how often a food item is sold out when students order more easily.

hchart(soldout_tbl, type = "column", hcaes(x = SoldOutFreq, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.3.8 Max Wait Tolerated

This table shows the longest waiting time students can accept, with the number and percentage of responses for each answer.

max_wait_tbl <- freq_table(data, MaxWaitTolerated, sort_desc = FALSE)
datatable(max_wait_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about the longest waiting time students can accept more easily.

hchart(max_wait_tbl, type = "column", hcaes(x = MaxWaitTolerated, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.4 Operational Perceptions and Policies

3.4.1 Notice External Students

This table shows how often students see students from other universities in the canteen, with the number and percentage of responses for each answer.

external_tbl <- freq_table(data, NoticeExternalStudents, sort_desc = FALSE)
datatable(external_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about how often students see students from other universities in the canteen more easily.

hchart(external_tbl, type = "column", hcaes(x = NoticeExternalStudents, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.4.2 Rule Clarity

This table shows whether the rules about who can use the canteen are clear, with the number and percentage of responses for each answer.

rule_clarity_tbl <- freq_table(data, RuleClarity, sort_desc = FALSE)
datatable(rule_clarity_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about whether the rules about who can use the canteen are clear more easily.

hchart(rule_clarity_tbl, type = "column", hcaes(x = RuleClarity, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.4.3 Priority Improvement

This table shows the one service stage students most want to improve, with the number and percentage of responses for each answer.

priority_tbl <- freq_table(data, PriorityImprovement)
datatable(priority_tbl, rownames = FALSE, options = list(dom = "t"))

This chart shows the same counts as the table above, so we can compare the answers about the one service stage students most want to improve more easily.

hchart(priority_tbl, type = "bar", hcaes(x = PriorityImprovement, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.5 Multi-Select and Open-Ended Responses

3.5.1 Bottleneck Stage

This table shows which service stage students think is the biggest bottleneck (raw answers, up to 2 options per person), with the number and percentage of responses for each answer.

bottleneck_tbl <- freq_table(data, BottleneckStage)
datatable(bottleneck_tbl, rownames = FALSE, options = list(dom = "tp", pageLength = 10))

This chart shows the same counts as the table above, so we can compare the answers about which service stage students think is the biggest bottleneck (raw answers, up to 2 options per person) more easily.

hchart(bottleneck_tbl, type = "bar", hcaes(x = BottleneckStage, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.5.2 Overcrowd Causes

This table shows what students think causes overcrowding and delays, with the number and percentage of responses for each answer.

causes_tbl <- freq_table(data, OvercrowdCauses)
datatable(causes_tbl, rownames = FALSE, options = list(dom = "tp", pageLength = 10))

This chart shows the same counts as the table above, so we can compare the answers about what students think causes overcrowding and delays more easily.

hchart(causes_tbl, type = "bar", hcaes(x = OvercrowdCauses, y = NumberOfResponses), name = "Responses") %>%
  hc_chart(zoomType = "xy")

3.5.3 Feedback Suggestions

This table lists the open-text suggestions and how many students wrote each one. Empty answers are shown as NA.

feedback_tbl <- freq_table(data, FeedbackSuggestions)
datatable(feedback_tbl, rownames = FALSE, options = list(dom = "tp", pageLength = 10))

4 Univariate analysis – numerical variables

4.1 Summary statistics

This table shows the main statistics (mean, median, mode, minimum, quartiles, maximum, range, IQR and variance) for the six satisfaction scores from 1 to 5.

# 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)
)

4.2 Distributions

4.2.1 SatQueueing

This table counts how many students gave each score from 1 to 5 for satisfaction with the queuing time and payment speed.

sat_queue_dist <- data %>%
  count(SatQueueing, name = "NumberOfResponses") %>%
  arrange(SatQueueing)

datatable(sat_queue_dist, rownames = FALSE, options = list(dom = "t"))

This chart shows the distribution of the satisfaction score for the queuing time and payment speed (1 = very dissatisfied, 5 = very satisfied).

hchart(sat_queue_dist, type = "column", hcaes(x = SatQueueing, y = NumberOfResponses), name = "SatQueueing") %>%
  hc_chart(zoomType = "xy")

4.2.2 SatFoodPickup

This table counts how many students gave each score from 1 to 5 for satisfaction with the food pickup time and food availability.

sat_food_dist <- data %>%
  count(SatFoodPickup, name = "NumberOfResponses") %>%
  arrange(SatFoodPickup)

datatable(sat_food_dist, rownames = FALSE, options = list(dom = "t"))

This chart shows the distribution of the satisfaction score for the food pickup time and food availability (1 = very dissatisfied, 5 = very satisfied).

hchart(sat_food_dist, type = "column", hcaes(x = SatFoodPickup, y = NumberOfResponses), name = "SatFoodPickup") %>%
  hc_chart(zoomType = "xy")

4.2.3 SatSeating

This table counts how many students gave each score from 1 to 5 for satisfaction with seat availability.

sat_seat_dist <- data %>%
  count(SatSeating, name = "NumberOfResponses") %>%
  arrange(SatSeating)

datatable(sat_seat_dist, rownames = FALSE, options = list(dom = "t"))

This chart shows the distribution of the satisfaction score for seat availability (1 = very dissatisfied, 5 = very satisfied).

hchart(sat_seat_dist, type = "column", hcaes(x = SatSeating, y = NumberOfResponses), name = "SatSeating") %>%
  hc_chart(zoomType = "xy")

4.2.4 SatCleanliness

This table counts how many students gave each score from 1 to 5 for satisfaction with table cleanliness and tray return.

sat_clean_dist <- data %>%
  count(SatCleanliness, name = "NumberOfResponses") %>%
  arrange(SatCleanliness)

datatable(sat_clean_dist, rownames = FALSE, options = list(dom = "t"))

This chart shows the distribution of the satisfaction score for table cleanliness and tray return (1 = very dissatisfied, 5 = very satisfied).

hchart(sat_clean_dist, type = "column", hcaes(x = SatCleanliness, y = NumberOfResponses), name = "SatCleanliness") %>%
  hc_chart(zoomType = "xy")

4.2.5 SatTotalTime

This table counts how many students gave each score from 1 to 5 for satisfaction with the total time spent in the canteen.

sat_time_dist <- data %>%
  count(SatTotalTime, name = "NumberOfResponses") %>%
  arrange(SatTotalTime)

datatable(sat_time_dist, rownames = FALSE, options = list(dom = "t"))

This chart shows the distribution of the satisfaction score for the total time spent in the canteen (1 = very dissatisfied, 5 = very satisfied).

hchart(sat_time_dist, type = "column", hcaes(x = SatTotalTime, y = NumberOfResponses), name = "SatTotalTime") %>%
  hc_chart(zoomType = "xy")

4.2.6 SatOverall

This table counts how many students gave each score from 1 to 5 for satisfaction with the canteen overall.

sat_overall_dist <- data %>%
  count(SatOverall, name = "NumberOfResponses") %>%
  arrange(SatOverall)

datatable(sat_overall_dist, rownames = FALSE, options = list(dom = "t"))

This chart shows the distribution of the satisfaction score for the canteen overall (1 = very dissatisfied, 5 = very satisfied).

hchart(sat_overall_dist, type = "column", hcaes(x = SatOverall, y = NumberOfResponses), name = "SatOverall") %>%
  hc_chart(zoomType = "xy")

4.3 Outliers

This table shows the lower and upper limits of the IQR rule for each satisfaction score, and how many answers fall outside these limits (possible outliers).

# 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")
)

These boxplots compare the six satisfaction scores side by side. The box shows the middle 50% of answers and the dots show outliers.

# 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"))

5 Bivariate analysis

5.1 VisitTime × FullnessLevel

This table counts the responses for each visit time and fullness level, and gives the percentage within each visit time.

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)
)

This stacked chart shows, for each visit time, how full the canteen was when students arrived.

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")

5.2 QueueTime × SatQueueing

This table shows the queuing satisfaction score (mean, median, quartiles, min and max) for each queue time group.

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)
)

These boxplots compare the queuing satisfaction score between students who wait different amounts of time in line.

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)"))

5.3 IUStudent × OvercrowdAlternative

This table counts what IU and non-IU students do when the canteen is overcrowded, with the percentage within each group.

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)
)

This chart compares the alternatives chosen by IU students and non-IU students when the canteen is overcrowded.

hchart(
  iu_alt_tbl,
  type = "bar",
  hcaes(x = OvercrowdAlternative, y = GroupPercent, group = IUStudent)
) %>%
  hc_yAxis(title = list(text = "Percentage Within Group (%)")) %>%
  hc_xAxis(title = list(text = "Alternative Action During Overcrowding")) %>%
  hc_chart(zoomType = "xy")

5.4 SatTotalTime × SatOverall

This table shows the overall satisfaction score for each level of satisfaction with the total time spent.

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")
)

These boxplots show how overall satisfaction changes with satisfaction with the total time spent in the canteen.

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)"))

5.5 FullnessLevel × SatSeating

This table shows the seating satisfaction score for each fullness level of the canteen.

fullness_seat_summary <- data %>%
  filter(!is.na(FullnessLevel), !is.na(SatSeating)) %>%
  group_by(FullnessLevel) %>%
  summarise(
    Responses  = n(),
    SatMean    = round(mean(SatSeating), 2),
    SatMedian  = median(SatSeating),
    SatQ1      = as.numeric(quantile(SatSeating, 0.25)),
    SatQ3      = as.numeric(quantile(SatSeating, 0.75)),
    SatMin     = min(SatSeating),
    SatMax     = max(SatSeating),
    .groups    = "drop"
  )

datatable(
  fullness_seat_summary,
  rownames = FALSE,
  options = list(dom = "t", scrollX = TRUE)
)

These boxplots compare the seating satisfaction score between different fullness levels.

fullness_seat_clean <- data %>%
  filter(!is.na(FullnessLevel), !is.na(SatSeating))

hcboxplot(
  x = fullness_seat_clean$SatSeating,
  var = fullness_seat_clean$FullnessLevel,
  outliers = TRUE
) %>%
  hc_chart(type = "column", zoomType = "xy") %>%
  hc_xAxis(title = list(text = "Canteen Fullness Level")) %>%
  hc_yAxis(title = list(text = "Seating Satisfaction Score (1–5)"))

5.6 IUStudent × NoticeExternalStudents

This table counts how often IU and non-IU students notice students from other universities, with the percentage within each group.

iu_notice_tbl <- data %>%
  filter(!is.na(IUStudent), !is.na(NoticeExternalStudents)) %>%
  count(IUStudent, NoticeExternalStudents, name = "Responses") %>%
  group_by(IUStudent) %>%
  mutate(GroupPercent = round(Responses / sum(Responses) * 100, 2)) %>%
  ungroup()

datatable(
  iu_notice_tbl,
  rownames = FALSE,
  options = list(dom = "t", scrollX = TRUE)
)

This chart compares how often IU students and non-IU students notice students from other universities in the canteen.

hchart(
  iu_notice_tbl,
  type = "column",
  hcaes(x = NoticeExternalStudents, y = GroupPercent, group = IUStudent)
) %>%
  hc_yAxis(title = list(text = "Percentage Within Group (%)")) %>%
  hc_xAxis(title = list(text = "How Often External Students Are Noticed")) %>%
  hc_chart(zoomType = "xy")

5.7 Correlation between satisfaction scores

This table shows the Spearman correlation between the six satisfaction scores. A value close to 1 means the two scores go up together.

# Spearman correlation (suitable for 1–5 ordinal scores)
sat_cor <- data %>%
  select(all_of(num_vars)) %>%
  cor(method = "spearman", use = "pairwise.complete.obs") %>%
  round(2)

datatable(
  as.data.frame(sat_cor),
  options = list(dom = "t", scrollX = TRUE)
)

This heatmap shows the same correlations with colours, so strong and weak relationships are easy to see.

hchart(sat_cor) %>%
  hc_title(text = "Spearman Correlation Between Satisfaction Scores")

6 Univariate analysis – Timestamp

This table shows how many dates had a given number of responses.

date_responses <- data %>%
  filter(!is.na(Timestamp)) %>%
  count(Date = as_date(Timestamp), name = "NumberOfResponses")

date_responses %>%
  count(NumberOfResponses, name = "NumberOfDates") %>%
  datatable(rownames = FALSE, options = list(dom = "t"))

This chart shows the number of survey responses collected on each date.

hchart(date_responses, type = "column",
       hcaes(x = Date, y = NumberOfResponses), name = "Responses") %>%
  hc_title(text = "Number of responses per date") %>%
  hc_chart(zoomType = "xy")

This table shows the number of responses for each day of the week.

data %>%
  filter(!is.na(Timestamp)) %>%
  mutate(Weekday = wday(Timestamp, label = TRUE, week_start = 1)) %>%
  count(Weekday, name = "NumberOfResponses", .drop = FALSE) %>%
  datatable(rownames = FALSE, options = list(dom = "t"))

This chart shows the number of responses for each hour of the day when the form was submitted.

hour_responses <- data %>%
  filter(!is.na(Timestamp)) %>%
  count(Hour = hour(Timestamp), name = "NumberOfResponses")

hchart(hour_responses, type = "column",
       hcaes(x = Hour, y = NumberOfResponses), name = "Responses") %>%
  hc_title(text = "Number of responses per hour of the day") %>%
  hc_xAxis(title = list(text = "Hour of the day")) %>%
  hc_chart(zoomType = "xy")

7 Missing values

This table lists the columns that have missing values, with the number and percentage of missing answers.

missing_df <- tibble(
  ColumnName     = names(data),
  MissingValues  = map_int(data, ~ sum(is.na(.x))),
  PercentMissing = round(MissingValues / nrow(data) * 100, 2)
) %>%
  filter(MissingValues > 0) %>%
  arrange(desc(MissingValues))

datatable(missing_df, rownames = FALSE, options = list(dom = "t"))

This table compares the missing feedback answers between IU students and non-IU students.

data %>%
  group_by(IUStudent) %>%
  summarise(Responses = n(),
            MissingFeedback = sum(is.na(FeedbackSuggestions))) %>%
  ungroup() %>%
  mutate(PercentMissing = round(MissingFeedback / Responses * 100, 2)) %>%
  datatable(rownames = FALSE, options = list(dom = "t"))

This table compares the missing feedback answers between the different visit times.

data %>%
  group_by(VisitTime) %>%
  summarise(Responses = n(),
            MissingFeedback = sum(is.na(FeedbackSuggestions))) %>%
  ungroup() %>%
  mutate(PercentMissing = round(MissingFeedback / Responses * 100, 2)) %>%
  datatable(rownames = FALSE, options = list(dom = "t"))

8 Duplicate check

This table shows respondents whose name appears more than once (ignoring upper/lower case and extra spaces). An empty table means there are no repeated names.

# Same respondent name (ignoring case and extra spaces) appearing more than once
data %>%
  mutate(NameKey = str_to_lower(str_squish(StudentName))) %>%
  group_by(NameKey) %>%
  filter(n() > 1) %>%
  ungroup() %>%
  select(Timestamp, StudentName, IUStudent, VisitTime, SatOverall) %>%
  arrange(StudentName) %>%
  datatable(rownames = FALSE, options = list(pageLength = 10, scrollX = TRUE))

This table shows responses submitted in the same minute and checks whether their answers are exact copies of each other.

# Responses submitted in the same minute: exact copy or different respondents?
data %>%
  mutate(ExactCopy = if_else(duplicated(select(., -Timestamp, -StudentName)) |
                               duplicated(select(., -Timestamp, -StudentName), fromLast = TRUE),
                             "Yes", "No")) %>%
  group_by(Timestamp) %>%
  filter(n() > 1) %>%
  ungroup() %>%
  select(Timestamp, StudentName, IUStudent, VisitTime, SatOverall, ExactCopy) %>%
  arrange(Timestamp) %>%
  datatable(rownames = FALSE, options = list(pageLength = 10, scrollX = TRUE))

This line counts responses that have exactly the same answers to every question (not counting the time and the name).

paste("Exact duplicate answers (ignoring Timestamp and StudentName):",
      sum(duplicated(data %>% select(-Timestamp, -StudentName))))
## [1] "Exact duplicate answers (ignoring Timestamp and StudentName): 0"

9 Data Cleaning

This table is the Data Problem Log. It lists every problem found in the raw data, how we fixed it, why, and how many values were changed. The steps below (9.1 to 9.19) show the code and the result of each fix.

datatable(problem_log, rownames = FALSE,
          options = list(dom = "t", pageLength = 30, scrollX = TRUE))

9.1 Load the raw data and rename the columns

We read the raw CSV file again with every column as text, so that nothing is changed by R before we look at it. Then we give the long survey questions short column names.

# trim_ws = FALSE keeps the extra spaces and na = character() keeps the empty cells as "",
# so we can see these problems and fix them ourselves in the next steps
raw <- read_csv(data_file, col_types = cols(.default = col_character()),
                trim_ws = FALSE, na = character())

# Empty table for the Data Problem Log
problem_log <- tibble(Step = integer(), Variable = character(), Problem = character(),
                      Fix = character(), Reason = character(), ValuesChanged = integer())

# Show a small table without search box or paging
dt_simple <- function(df, caption = NULL) {
  datatable(df, rownames = FALSE, caption = caption,
            options = list(dom = "t", pageLength = 50, scrollX = TRUE))
}

# Before/after table: each original answer, the clean answer and how many responses
show_changes <- function(before, after, caption = NULL) {
  tibble(OriginalAnswer = before, CleanAnswer = as.character(after)) %>%
    count(OriginalAnswer, CleanAnswer, name = "Responses") %>%
    mutate(Changed = if_else(coalesce(OriginalAnswer != CleanAnswer, TRUE), "Yes", "No")) %>%
    arrange(desc(Changed), desc(Responses)) %>%
    dt_simple(caption = caption)
}

add_log <- function(log, variable, problem, fix, reason, n) {
  bind_rows(log, tibble(Step = nrow(log) + 1L, Variable = variable, Problem = problem,
                        Fix = fix, Reason = reason, ValuesChanged = as.integer(n)))
}

clean <- raw
names(clean) <- new_names

problem_log <- add_log(problem_log, "All columns",
  "Column names are full survey questions (long, with line breaks and extra spaces)",
  "Renamed to short names", "Short names are easier to use in code and tables",
  sum(names(raw) != new_names))

tibble(OriginalQuestion = str_trunc(str_squish(names(raw)), 90), NewName = new_names) %>%
  dt_simple(caption = paste("Raw data:", nrow(clean), "rows and", ncol(clean), "columns. Original question and new short name."))

9.2 Remove extra spaces

Some answers have spaces at the start or the end (for example “FPT University”). These make the same answer look like two different answers, so we remove them.

before <- clean
clean <- clean %>% mutate(across(everything(), str_squish))

n_spaces <- sum(before != clean, na.rm = TRUE)
problem_log <- add_log(problem_log, "All text columns", "Extra spaces before/after answers",
  "Removed extra spaces with str_squish()", "The same answer must have the same text", n_spaces)

# Cells that had extra spaces (quotes show where the spaces were)
map_dfr(names(clean), function(v) {
  idx <- which(before[[v]] != clean[[v]])
  tibble(Column = rep(v, length(idx)),
         OriginalAnswer = paste0('"', before[[v]][idx], '"'),
         CleanAnswer = paste0('"', clean[[v]][idx], '"'))
}) %>%
  dt_simple(caption = paste("Cells changed:", n_spaces))

9.3 Missing values: convert empty cells to NA

In the raw file, a missing answer is an empty cell (““). R does not treat an empty text as missing, so we change every empty cell, and common placeholders such as”N/A”, “NA”, “None”, “-” or “.”, into the standard NA value.

na_codes <- c("", "NA", "N/A", "n/a", "None", "none", "-", ".")

missing_before <- tibble(ColumnName = names(clean),
                         EmptyOrPlaceholder = map_int(clean, ~ sum(.x %in% na_codes)))

clean <- clean %>% mutate(across(everything(), ~ if_else(.x %in% na_codes, NA_character_, .x)))

n_na <- sum(missing_before$EmptyOrPlaceholder)
problem_log <- add_log(problem_log, "All columns (empty cells found only in FeedbackSuggestions)",
  "Missing answers stored as empty text (\"\") instead of NA",
  "Converted empty cells and placeholders to NA",
  "R can only count and handle missing values when they are NA", n_na)

missing_before %>%
  filter(EmptyOrPlaceholder > 0) %>%
  mutate(NAAfterCleaning = map_int(ColumnName, ~ sum(is.na(clean[[.x]])))) %>%
  dt_simple(caption = "Columns with empty cells: number of empty cells before and NA values after this step")

9.4 Timestamp: convert text to date-time

The timestamp is stored as text (day/month/year hour:minute). We convert it to a real date-time and check that no value is lost.

clean <- clean %>% mutate(Timestamp = dmy_hm(Timestamp))

n_bad_time <- sum(is.na(clean$Timestamp))
problem_log <- add_log(problem_log, "Timestamp", "Date-time stored as text",
  "Converted to date-time (POSIXct)", "Needed to analyse responses by date and hour", nrow(clean))

tibble(OriginalText = raw[[1]][1:5],
       CleanDateTime = format(clean$Timestamp[1:5], "%Y-%m-%d %H:%M")) %>%
  dt_simple(caption = paste("First 5 rows before and after. Timestamps that could not be converted:", n_bad_time))

9.5 IUStudent: recode to Yes / No

This is a Yes/No question, but students from other universities typed the name of their university (in many spellings) or “no” in lower case. Every answer that is not “Yes” means the person is not an IU student, so we recode it to “No”.

before <- clean$IUStudent
clean <- clean %>%
  mutate(IUStudent = factor(if_else(str_to_lower(IUStudent) == "yes", "Yes", "No"),
                            levels = c("Yes", "No")))

n_iu <- sum(before != as.character(clean$IUStudent))
problem_log <- add_log(problem_log, "IUStudent",
  "University names and lower-case \"no\" in a Yes/No question",
  "Recoded: \"Yes\" stays Yes, every other answer becomes No",
  "Only IU vs non-IU is needed for the analysis", n_iu)

show_changes(before, clean$IUStudent, caption = "IUStudent: original answer, clean answer and number of responses")

9.6 VisitTime: merge two time formats

The same time slot is written in two formats (“11:00 – 11:59” and “11:00 AM – 11:59 AM”), probably because the form was changed during the survey. We use one format and put the slots in time order.

before <- clean$VisitTime
time_levels <- c("Before 11:00 AM", "11:00 AM – 11:59 AM", "12:00 PM – 12:59 PM", "1:00 PM or later")

clean <- clean %>%
  mutate(VisitTime = case_when(
           VisitTime == "11:00 – 11:59" ~ "11:00 AM – 11:59 AM",
           VisitTime == "12:00 – 12:59" ~ "12:00 PM – 12:59 PM",
           TRUE ~ VisitTime),
         VisitTime = factor(VisitTime, levels = time_levels, ordered = TRUE))

n_time <- sum(before != as.character(clean$VisitTime))
problem_log <- add_log(problem_log, "VisitTime", "Same time slot written in two formats",
  "Merged into the AM/PM format; ordered by time", "One time slot must be one category", n_time)

show_changes(before, clean$VisitTime, caption = "VisitTime: original answer, clean answer and number of responses")

9.7 VisitPurpose: one answer with two options

This is a single-choice question, but one student gave two options. We keep the first option, which is also the most common answer.

before <- clean$VisitPurpose
clean <- clean %>%
  mutate(VisitPurpose = str_remove(VisitPurpose, ";.*$") %>% str_squish() %>% factor())

n_purpose <- sum(before != as.character(clean$VisitPurpose))
problem_log <- add_log(problem_log, "VisitPurpose", "Two options in a single-choice question",
  "Kept the first option", "Each student should have one main purpose", n_purpose)

show_changes(before, clean$VisitPurpose, caption = "VisitPurpose: original answer, clean answer and number of responses")

9.8 SeatFindTime: fix a missing bracket

The option “3–5 minutes (Had to walk around the canteen to find a seat)” sometimes has no closing bracket, so it is counted as a different answer. We add the bracket and put the options in time order.

before <- clean$SeatFindTime
seat_levels <- c("Under 2 minutes (Found a seat right away)",
                 "3–5 minutes (Had to walk around the canteen to find a seat)",
                 "6–10 minutes (Had to wait for someone to leave)",
                 "More than 10 minutes (Extremely difficult to find a seat)")

clean <- clean %>%
  mutate(SeatFindTime = if_else(str_detect(SeatFindTime, "find a seat$"),
                                paste0(SeatFindTime, ")"), SeatFindTime),
         SeatFindTime = factor(SeatFindTime, levels = seat_levels, ordered = TRUE))

n_seat <- sum(before != as.character(clean$SeatFindTime))
problem_log <- add_log(problem_log, "SeatFindTime", "Missing closing bracket in one option",
  "Added the bracket; ordered by time", "The same option must have the same text", n_seat)

show_changes(before, clean$SeatFindTime, caption = "SeatFindTime: original answer, clean answer and number of responses")

9.9 TableCleanliness: translate the Vietnamese answer

Some students chose an answer partly written in Vietnamese (“Frequently còn đĩa bẩn / rác chưa dọn”). It means “dirty dishes or trash are often left”, so we replace it with the English option that has the same meaning. We also order the options from clean to dirty.

before <- clean$TableCleanliness
clean_levels <- c("The table is always clean and dry",
                  "Fairly clean (Only a few small water marks)",
                  "Dirty dishes or leftover trash are often left on the table",
                  "Very unhygienic (Have to clean the table myself before eating)")

clean <- clean %>%
  mutate(TableCleanliness = if_else(str_starts(TableCleanliness, "Frequently"),
                                    "Dirty dishes or leftover trash are often left on the table",
                                    TableCleanliness),
         TableCleanliness = factor(TableCleanliness, levels = clean_levels, ordered = TRUE))

n_cleanliness <- sum(before != as.character(clean$TableCleanliness))
problem_log <- add_log(problem_log, "TableCleanliness", "Answer partly written in Vietnamese",
  "Replaced with the English option with the same meaning", "All answers must use the same option list",
  n_cleanliness)

show_changes(before, clean$TableCleanliness, caption = "TableCleanliness: original answer, clean answer and number of responses")

9.10 Other single-choice questions: set the data type

These questions have clean answers, so no value is changed. We only set the right type: ordered factor when the answers have a natural order, and factor when they do not. Then we check that no answer became NA.

clean <- clean %>%
  mutate(
    FullnessLevel          = factor(FullnessLevel,    levels = lv_fullness,  ordered = TRUE),
    QueueTime              = factor(QueueTime,        levels = lv_wait,      ordered = TRUE),
    FoodWaitTime           = factor(FoodWaitTime,     levels = lv_wait,      ordered = TRUE),
    SoldOutFreq            = factor(SoldOutFreq,      levels = lv_soldout,   ordered = TRUE),
    TableDifficulty        = factor(TableDifficulty,  levels = lv_tablediff, ordered = TRUE),
    MaxWaitTolerated       = factor(MaxWaitTolerated, levels = lv_maxwait,   ordered = TRUE),
    NoticeExternalStudents = factor(NoticeExternalStudents, levels = lv_notice, ordered = TRUE),
    RuleClarity            = factor(RuleClarity,      levels = lv_rule,      ordered = TRUE),
    across(c(StayReason, OvercrowdAlternative, PriorityImprovement), factor)
  )

check_vars <- c("FullnessLevel", "QueueTime", "FoodWaitTime", "SoldOutFreq", "TableDifficulty",
                "MaxWaitTolerated", "NoticeExternalStudents", "RuleClarity",
                "StayReason", "OvercrowdAlternative", "PriorityImprovement")
tibble(Variable = check_vars,
       NewType = map_chr(check_vars, ~ class(clean[[.x]])[1]),
       Categories = map_int(check_vars, ~ nlevels(clean[[.x]])),
       NewNA = map_int(check_vars, ~ sum(is.na(clean[[.x]]) & !is.na(raw[[which(new_names == .x)]])))) %>%
  dt_simple(caption = "New data type, number of categories, and NA values created by the conversion (0 = no answer lost)")

9.11 BottleneckStage: split into one Yes/No column per stage

Students could choose up to 2 stages, but the answers are joined with different separators (“,” and “;”), some are written in their own words (for example “Queuing to order”, “Prepare food in the kitchen”) and some students chose more than 2. We search for key words to find which of the 5 stages each student mentioned and make one TRUE/FALSE column for each stage. Students who chose more than 2 stages are kept but flagged.

clean <- clean %>%
  mutate(
    BN_Queueing  = str_detect(BottleneckStage, regex("queu", ignore_case = TRUE)),
    BN_Payment   = str_detect(BottleneckStage, regex("payment", ignore_case = TRUE)),
    BN_Kitchen   = str_detect(BottleneckStage, regex("kitchen", ignore_case = TRUE)),
    BN_Pickup    = str_detect(BottleneckStage, regex("pickup|collect", ignore_case = TRUE)),
    BN_Seating   = str_detect(BottleneckStage, regex("seat", ignore_case = TRUE)),
    BN_NumStages = BN_Queueing + BN_Payment + BN_Kitchen + BN_Pickup + BN_Seating,
    BN_OverLimit = BN_NumStages > 2
  )

official_stages <- c("Queueing to place an order", "Order processing and payment",
                     "Food preparation in the kitchen",
                     "Waiting to collect food at the pickup counter",
                     "Finding a seat due to limited seating capacity")
n_free_text <- raw[[17]] %>%
  str_split(";\\s*|,\\s*(?=[A-Z])") %>%
  map_lgl(~ any(!str_squish(.x) %in% official_stages)) %>%
  sum()
n_over <- sum(clean$BN_OverLimit)

problem_log <- add_log(problem_log, "BottleneckStage",
  "Mixed separators and free-text answers in a multi-select question",
  "Split into 5 TRUE/FALSE columns (BN_*) using key words",
  "Each stage can then be counted correctly", n_free_text)
problem_log <- add_log(problem_log, "BottleneckStage",
  "More than 2 stages chosen (rule: up to 2)",
  "Kept, but flagged in BN_OverLimit", "The answers are still valid opinions", n_over)

clean %>%
  summarise(across(BN_Queueing:BN_Seating, sum)) %>%
  pivot_longer(everything(), names_to = "NewColumn", values_to = "StudentsWhoChoseIt") %>%
  mutate(Stage = official_stages, .before = 1) %>%
  dt_simple(caption = paste0("New TRUE/FALSE columns. Free-text answers mapped: ", n_free_text,
                             "; students with more than 2 stages (flagged): ", n_over))

9.12 OvercrowdCauses: merge answers with the same meaning

Two pairs of answers mean the same thing: “Students occupying tables for too long…” is the same as “Awareness issue: Lingering at tables…”, and “The layout of shelving units…” is the same as “Inefficient counter layout and traffic flow”. We merge each pair into the official option.

before <- clean$OvercrowdCauses
clean <- clean %>%
  mutate(OvercrowdCauses = case_when(
           str_starts(OvercrowdCauses, "Students occupying tables") ~
             "Awareness issue: Lingering at tables long after eating",
           str_starts(OvercrowdCauses, "The layout of shelving units") ~
             "Inefficient counter layout and traffic flow",
           TRUE ~ OvercrowdCauses),
         OvercrowdCauses = factor(OvercrowdCauses))

n_causes <- sum(before != as.character(clean$OvercrowdCauses))
problem_log <- add_log(problem_log, "OvercrowdCauses", "Different texts with the same meaning",
  "Merged into the official option", "One cause must be one category", n_causes)

show_changes(before, clean$OvercrowdCauses, caption = "OvercrowdCauses: original answer, clean answer and number of responses")

9.13 FeedbackSuggestions: keep missing answers

This question was optional, so many students left it empty. An empty answer is not an error, so we do not delete or fill these rows. We keep them as NA and add a column that shows who gave feedback.

n_missing_fb <- sum(is.na(clean$FeedbackSuggestions))
clean <- clean %>% mutate(HasFeedback = !is.na(FeedbackSuggestions))

problem_log <- add_log(problem_log, "FeedbackSuggestions", "Missing answers in an optional question",
  "Kept as NA (not deleted, not filled); added HasFeedback (TRUE/FALSE)",
  "Deleting these rows would lose 45% of the data for no reason", 0)

count(clean, HasFeedback, name = "Responses") %>%
  mutate(Meaning = if_else(HasFeedback, "Wrote a suggestion", "Left it empty (kept as NA)"), .before = 1) %>%
  dt_simple(caption = "Feedback answers after cleaning")

9.14 Satisfaction scores: check the range and the outliers

The scores must be whole numbers from 1 to 5. We convert them to integers and count impossible values. Scores of 1 or 2 are marked as outliers by the IQR rule only because most answers are 3–5; they are real opinions, so we keep them.

clean <- clean %>% mutate(across(all_of(num_vars), as.integer))

n_impossible <- sum(sapply(num_vars, function(v) sum(clean[[v]] < 1 | clean[[v]] > 5, na.rm = TRUE)))
n_iqr_outliers <- sum(outliers_df$BelowLower + outliers_df$AboveUpper)

problem_log <- add_log(problem_log, "Sat* (6 scores)", "Scores read as text",
  "Converted to integer; checked range 1-5", "Likert scores are whole numbers", 0)
problem_log <- add_log(problem_log, "Sat* (6 scores)",
  paste0("IQR outliers (low scores of 1-2): ", n_iqr_outliers, " values; impossible values: ", n_impossible),
  "Kept (no change)", "They are valid answers on the 1-5 scale, not errors", 0)

tibble(Variable = num_vars,
       Min = map_int(num_vars, ~ min(clean[[.x]])),
       Max = map_int(num_vars, ~ max(clean[[.x]])),
       OutOfRange = map_int(num_vars, ~ sum(clean[[.x]] < 1 | clean[[.x]] > 5)),
       IQROutliersKept = outliers_df$BelowLower + outliers_df$AboveUpper) %>%
  dt_simple(caption = "Range check of the satisfaction scores (OutOfRange must be 0)")

9.15 Inconsistent answers: flag them

Some students give a total-time score that is very different (2 points or more) from the average of their queueing, food pickup and seating scores. These answers may be careless, but we cannot be sure, so we keep them and add a flag. They can be checked separately in later analysis.

clean <- clean %>%
  mutate(InconsistentTime = abs(SatTotalTime - (SatQueueing + SatFoodPickup + SatSeating) / 3) >= 2)

n_inconsistent <- sum(clean$InconsistentTime)
problem_log <- add_log(problem_log, "SatTotalTime", "Total-time score far from the 3 stage scores",
  "Kept, but flagged in InconsistentTime", "Not enough evidence to delete them", n_inconsistent)

clean %>%
  filter(InconsistentTime) %>%
  select(SatQueueing, SatFoodPickup, SatSeating, SatTotalTime) %>%
  dt_simple(caption = paste("Flagged responses:", n_inconsistent))

9.16 Duplicates: check and remove

We look for exact copies of a response (same answers to all questions) and for names that appear more than once. Any exact copy would be removed.

dup_rows <- duplicated(clean %>% select(-Timestamp, -StudentName))
dup_names <- duplicated(str_to_lower(clean$StudentName))
n_dup <- sum(dup_rows | dup_names)

clean <- clean[!(dup_rows | dup_names), ]
problem_log <- add_log(problem_log, "All columns", "Duplicate responses",
  "Checked exact copies and repeated names; removed if found", "One person should be counted once",
  n_dup)

tibble(Check = c("Exact copies of a response", "Repeated names", "Rows removed", "Rows left"),
       Result = c(sum(dup_rows), sum(dup_names), n_dup, nrow(clean))) %>%
  dt_simple(caption = "Duplicate check")

9.17 StudentName: add a respondent ID

We keep the student names and add a simple respondent ID (R001, R002, …) as the first column. The ID gives every response a short, unique key that is easy to use in tables and joins.

clean <- clean %>%
  mutate(RespondentID = sprintf("R%03d", row_number())) %>%
  select(RespondentID, StudentName, everything())

problem_log <- add_log(problem_log, "RespondentID (new)", "No short unique key for each response",
  "Added RespondentID (R001, R002, ...); StudentName is kept", "Easy to identify and join responses",
  0)

clean %>%
  select(RespondentID, StudentName, Timestamp, IUStudent) %>%
  head(5) %>%
  mutate(Timestamp = format(Timestamp, "%Y-%m-%d %H:%M")) %>%
  dt_simple(caption = "First 5 rows: RespondentID is added and StudentName is kept")

9.18 Final check of the clean data

This table shows the type, number of different values and missing values of every column in the clean data.

clean_overview <- tibble(
  ColumnName     = names(clean),
  DataType       = map_chr(clean, ~ class(.x)[1]),
  UniqueValues   = map_int(clean, ~ n_distinct(.x, na.rm = TRUE)),
  MissingValues  = map_int(clean, ~ sum(is.na(.x)))
)

datatable(clean_overview, rownames = FALSE, options = list(dom = "t", pageLength = 40, scrollX = TRUE))

These numbers summarise the cleaning and can be reused in the executive summary.

clean_summary <- tibble(
  Measure = c("Rows in raw data", "Columns in raw data", "Rows in clean data", "Columns in clean data",
              "Rows removed", "Values changed (total)", "Problems logged"),
  Value   = c(nrow(raw), ncol(raw), nrow(clean), ncol(clean),
              nrow(raw) - nrow(clean), sum(problem_log$ValuesChanged), nrow(problem_log))
)

datatable(clean_summary, rownames = FALSE, options = list(dom = "t"))

9.19 Save the clean data

We save the clean data and the problem log as a new file in the data/clean folder. The raw file stays unchanged.

dir.create("data/clean", recursive = TRUE, showWarnings = FALSE)
save(clean, problem_log, clean_summary, file = "data/clean/IUCanteenSurvey_Clean.Rdata")

tibble(File = "data/clean/IUCanteenSurvey_Clean.Rdata",
       Objects = "clean, problem_log, clean_summary",
       Saved = if_else(file.exists("data/clean/IUCanteenSurvey_Clean.Rdata"), "Yes", "No")) %>%
  dt_simple()