title: Replacing NA with observed values?
body: <p>I have a dataset that contains multiple observations per person. In some cases an individual will have their ethnicity recorded in some rows but missing in others. In R, how can I replace the NA's with the ethnicity stated in the other rows without having to manually change them? </p>
  
  <p>Example:</p>
  
  <pre><code>PersonID        Ethnicity
     1                A
     1                A
     1                NA
     1                NA
     1                A
     2                NA
     2                B
     2                NA
     3                NA
     3                NA
     3                A
     3                NA
  </code></pre>
  
  <p>Need:</p>
  
  <pre><code>PersonID        Ethnicity
     1                A
     1                A
     1                A
     1                A
     1                A
     2                B
     2                B
     2                B
     3                A
     3                A
     3                A
     3                A
  </code></pre>