A survey summary can look reasonable while quietly using the wrong denominator. A skipped answer is not the same thing as the lowest response, and it should not become a zero just because that makes a calculation easier.

This short example uses synthetic data only and base R. It keeps the number of missing answers visible, including when a response category has no observations.

1. Start with the question and its valid values

Suppose a questionnaire asks respondents to rate satisfaction from 1 to 5. Record the meaning of those labels in a codebook before analysis. In this example, NA means the answer is missing. Zero is not a valid response.

satisfaction <- c(2, 3, 4, 3, 5, 2, NA, 4, 3, 5, 4, 1) stopifnot(all(is.na(satisfaction) | satisfaction %in% 1:5)) n_total <- length(satisfaction) n_missing <- sum(is.na(satisfaction)) n_valid <- sum(!is.na(satisfaction)) 

The check stops the script when an invalid value enters the data. It does not silently turn an unexpected value into a missing answer. In a real workflow, investigate the source and document any correction.

2. Keep every response category in the table

Calling table() directly can omit unobserved categories. Specify the questionnaire levels so that a category with no responses still appears as a zero count.

counts <- table(factor(satisfaction, levels = 1:5)) result <- data.frame( response = names(counts), count = as.integer(counts), percent_of_valid = if (n_valid > 0) { round(100 * as.integer(counts) / n_valid, 1) } else { rep(NA_real_, 5) } ) print(result) cat("Total:", n_total, "Valid:", n_valid, "Missing:", n_missing, "\n") 

There are 12 entries, 11 valid answers and one missing answer. Counts for categories 1 through 5 are 1, 2, 3, 3 and 2. The corresponding percentages of valid answers are approximately 9.1%, 18.2%, 27.3%, 27.3% and 18.2%. Their rounded sum can differ slightly from 100%.

The explicit n_valid > 0 branch matters. If everybody skips the question, the counts are zero but percentages are undefined. Reporting 0% for every category would hide that distinction.

3. State the denominator when reporting

For category 4, the count is 3. Dividing by 11 gives 27.3% of valid answers. Dividing by 12 gives 25% of everyone in this example. Both calculations answer a different question; the table heading should say which one you used.

Do not replace NA with zero and include it in a mean. That would introduce a response outside the questionnaire scale. For a single ordinal item, begin with the response distribution. Whether a numerical summary or model is appropriate depends on the measurement assumptions and research design.

4. Save the decisions with the output

dir.create("survey-output", showWarnings = FALSE) write.csv(result, "survey-output/satisfaction.csv", row.names = FALSE) writeLines( c("Data: synthetic demonstration only", "Valid satisfaction responses: integers 1 to 5", "Missing answers: NA; excluded from percentage denominator", paste("Total:", n_total, "Valid:", n_valid, "Missing:", n_missing)), "survey-output/analysis-notes.txt" ) writeLines(capture.output(sessionInfo()), "survey-output/session-info.txt") 

Keep an unchanged raw-data copy and perform cleaning in a separate script. If a survey uses codes such as 99 for missingness, map them to NA deliberately according to the codebook. Never assume that the largest number is a missing-value code.

This example describes twelve invented observations. It supports no causal conclusion or population estimate. For real research, report sampling, exclusions, missing-data handling and the limits of the design.

A small checklist before sharing a table

  • Are all values valid according to the questionnaire?
  • Are missing responses counted separately?
  • Are zero-count categories retained?
  • Is the denominator stated?
  • Are the data and any interpretation appropriate to share publicly?

The extended example, including a numeric-variable summary and chart export, is in the survey data analysis guide on GitHub.

About the author: David Jakoda is the founder of Ghostwriter Akademie in Winterthur, Switzerland, providing writing consultation, proofreading, editing and data-analysis support. This post was prepared with AI assistance and uses no client data.