title: ifelse rows the same in R
body: <p>I have a dataframe that looks like this: </p>
  
  <pre><code>&gt; df&lt;-data.frame(A=c(NA,1,2,3,4),B=c(NA,5,NA,3,4),C=c(NA,NA,NA,NA,4))
  &gt; df
     A  B  C
  1 NA NA NA
  2  1  5 NA
  3  2 NA NA
  4  3  3 NA
  5  4  4  4
  </code></pre>
  
  <p>I am trying to create a "D" column based on the row values in df, where D gets an NA if the values in the row are different (i.e. row 2) or all NAs (i.e. row 1), and the value in the row if the values in that row are the same, excluding NAs (i.e. rows 3, 4, 5). This would produce a vector and dataframe that looks like this:</p>
  
  <pre><code>&gt; df$D&lt;-c(NA,NA,2,3,4)
  &gt; df
     A  B  C  D
  1 NA NA NA NA
  2  1  5 NA NA
  3  2 NA NA  2
  4  3  3 NA  3
  5  4  4  4  4
  </code></pre>
  
  <p>Thank you in advance for your suggestions.</p>