title: Parsing out data from one variable using complex rules in R
body: <p>I am importing data into R from another source (i.e., I cannot easily change the in-coming format/values).</p>
  
  <p>Among the variables is one that include one or more of these possible values:</p>
  
  <ul>
  <li>Mother (biological mother, foster mother, step mother, etc.)</li>
  <li>Father (biological father, foster father, step father, etc.)</li>
  <li>Grandparent(s) (biological, foster, step, etc.)</li>
  <li>Brother(s) older than 18</li>
  <li>Sister(s) older than 18</li>
  <li>Other adults (aunts, uncles, etc.)</li>
  </ul>
  
  <p>all within the same "cell" so that possible data look like:</p>
  
  <p><strong>Sample Input Data Frame (df)</strong></p>
  
  <pre><code>df &lt;- read.table(text =
  "row lives.with.whom
    1  'Mother (biological mother, foster mother, step mother, etc.), Father (biological father, foster father, step father, etc.), Grandparent(s) (biological, foster, step, etc.), Brother(s) older than 18, Sister(s) older than 18, Other adults (aunts, uncles, etc.)'
    2  ''
    3  'Mother (biological mother, foster mother, step mother, etc.), Sister(s) older than 18'
    4  'Mother (biological mother, foster mother, step mother, etc.), Father (biological father, foster father, step father, etc.)'", header = T)
  </code></pre>
  
  <p>Within <code>R</code>, how could I efficiently create rules to parse out these responses into separate columns, one column for each type of family member, so that the output would look like this:</p>
  
  <p><strong>Sample Output Data Frame</strong></p>
  
  <pre><code>mother &lt;- c(1,0,1,1)
  father &lt;- c(1,0,0,1)
  adult.brother &lt;- c(1,0,0,0)
  adult.sister &lt;- c(1,0,1,0)
  grandparent &lt;- c(1,0,0,0)
  other.adult &lt;- c(1,0,0,0)
  output.df &lt;- cbind(mother, father, adult.brother, adult.sister, grandparent, other.adult)
  colnames(output.df) &lt;- c("Mother", "Father", "Brother", "Sister", "Grandparent", "Other adult")
  output.df
  
       Mother Father Brother Sister Grandparent Other adult
  [1,]      1      1       1      1           1           1
  [2,]      0      0       0      0           0           0
  [3,]      1      0       0      1           0           0
  [4,]      1      1       0      0           0           0
  </code></pre>
  
  <p>TIA</p>