title: For loops with conditional statements to create a new dataframe
body: <p>I have a dataframe containing a column for site, family and visit number (visit_no). The sites have differing visit numbers (2 or 3) and different families recorded per visit and per site:</p>
  <pre><code>   site        family visit_no
  1    A1  Scarabaeidae        1
  2    A1     Clambidae        1
  3    A1     Carabidae        1
  4    A1     Carabidae        2
  5    A1     Clambidae        2
  6    A1  Scarabaeidae        2
  7    A1     Leiodidae        3
  8    A1     Clambidae        3
  9    A1     Carabidae        3
  10   A2  Scarabaeidae        1
  11   A2     Carabidae        1
  12   A2 Staphylinidae        1
  13   A2 Curculionidae        2
  14   A2  Scarabaeidae        2
  15   A2 Staphylinidae        2
  16   A3 Staphylinidae        1
  17   A3     Carabidae        1
  18   A3 Curculionidae        1
  19   A3     Leiodidae        2
  20   A3     Clambidae        2
  21   A3      Carbidae        2
  22   A3   Phalacridae        3
  23   A3     Carabidae        3
  24   A3 Curculionidae        3
  </code></pre>
  <p>I want to fill a dataframe that records for each visit at each site whether the family Scarabaeidae was present (1) or absent (0). Where a site has a lower visit number than other sites, I want the visit number column to record NA. This would look like so:</p>
  <pre><code>  site    1    2    3
  1   A1    1    1    0
  2   A2    1    1    NA
  3   A3    0    0    0
  </code></pre>
  <p>Is there a way to do this using conditional for loops?</p>