title: Manipulate a dataframe (select specific variables) using a general IF condition for the whole dataframe
body: <p>I'm trying to select specific set of variables using an if condition, on variables within the dataframe.</p>
  <pre><code>set.seed(123)
  X1 &lt;- sample(0:1, 10, replace = TRUE)
  X2 &lt;- sample(1:5, 10, replace = TRUE)
  X3 &lt;- sample(1:5, 10, replace = TRUE)
  X4 &lt;- seq(1:10)
  X5 &lt;- seq(1:10)
  
  df &lt;- data.frame(X1,X2,X3,X4,X5)
  
  df_result &lt;- ifelse(all.equal(df$X4 , df$X5) , df[ , 1:2], df)
  </code></pre>
  <p>This code turns df_result into a list and not a dataframe.
  What I'm trying to do, is if all of the values of X4 and X5 are exactly the same, then I want to keep first two columns, otherwise keep the dataframe as it is. It's specifically those two variables I want to keep using an instruction. I'm not trying to remove duplicated variables.
  Is it possible to manipulate a dataframe this way? Any help greatly appreciated. Thanks</p>