Turn a wide survey export into analysis-ready rows
Use pivoting to convert repeated question columns into tidy survey responses.
Convert three score columns into a tidy survey table. Tidy data makes repeated measures explicit. Not quite: the code answers today’s survey but fails the moment the vendor changes or adds questions. 1. Select repeated columns Identify score columns with a pattern such as matches("^q\d+_score$"). Pattern selection makes the code resilient when the next survey adds q4_score. 2. Pivot longer Use pivot_longer(..., names_to = "question_id", values_to = "score", names_pattern = "(q\d+)_score"). Question identity becomes data rather than a column-name convention. 3. Join meanings Join a question dictionary so charts use stable labels instead of raw vendor names. Human-readable labels are…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in