Condense matrix of values into one column?
You can use quite easily using the dplyr and tidyr packages as follows:
df %&gt;%
    # convert the columns to rows
    gather(key=&quot;response&quot;, value=&quot;value&quot;, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10) %&gt;%
    # select only rows where the reponse corresponds to the question
    filter(qnum == substr(response, 2, numchar(response)))