title: How to easily merge a table to unique elements of itself?
body: <p>I have this data frame: </p>
  
  <pre><code>df &lt;- data.frame(group=rep(1:3,each=3),
                   question=c("1.1.1. question 1","1.1.1.1. question1 with conditional","2.2.2.2. question2 with condtional", "2.2.2. question2","1.1.1.10. question 1 with conditional","3.3.3. question 3","3.3.3.2. question 3 with conditional","2.2.2.1. question 2 with conditional","3.3.3. Descirbe section 2.8"),
                   answer=c("yes","no","text","no","text","hello","yes","text","yes"),
                   parent_question=c("1.1.1. question 1","1.1.1. question 1","2.2.2. question2","2.2.2. question2","1.1.1. question 1","3.3.3. question 3","3.3.3. question 3","2.2.2. question2","3.3.3. Descirbe section 2.8"),
                   answer_parent=c("yes","yes","","","","","yes","","yes"))
  </code></pre>
  
  <p>What I want to do is create two new columns, called parent_question, and parent_answer.<br>
  So the parent_question to 1.1.1. is 1.1.1. and the parent question to 1.1.1.1. is 1.1.1. I know how do this by creating a parent_question dictionary and then merging it with this data set. And the parent_answer 1.1.1.1. is the answer to the parent_question 1.1.1. Is there an easy way to do this without creating a separate table for parent questions and parent answers and then merging them with the data?  </p>