title: How do you loop for n-columns and use conditionals?
body: <p>I'm trying to make a loop for a table that will be generated in 'xtable'.</p>
  
  <p>This is what I did "manually" together is here:</p>
  
  <p><strong>What I want to get</strong></p>
  
  <pre><code>library(dplyr)
  X1 = c(4.70e1, 4.72e1, 4.76e1, 2.73e20)
  X2 = c(4.67e1, 4.69e1, 4.77e1, 2.05e20)
  col.nam = c("AIC(n)", "HQ(n)", "SC(n)", "FPE(n)")
  tab.out = data.frame(col.nam, X1, X2)
  
  n.tab = tab.out %&gt;%
    mutate(test1 = if_else(tab.out$X1 &lt; tab.out$X2,
                           paste0(X1,"$^{*}$"),
                           paste0(X1)),
           test2 = if_else(tab.out$X2 &lt; tab.out$X1,
                           paste0(X2,"\\textsuperscript{*}"),
                           paste0(X2)))%&gt;%
    select(col.nam, test1, test2)
  
  #  col.nam      test1                        test2
  #1  AIC(n)         47     46.7\\textsuperscript{*}
  #2   HQ(n)       47.2     46.9\\textsuperscript{*}
  #3   SC(n) 47.6$^{*}$                         47.7
  #4  FPE(n)   2.73e+20 2.05e+20\\textsuperscript{*}
  </code></pre>
  
  <p>I want to make a loop for n-columns using conditionals as seen below in the code (<strong>My current ugly and error-prone fix</strong>):</p>
  
  <p><strong>Lo que obtuve ?</strong></p>
  
  <pre><code>tab.out = data.frame(X1, X2)
  tab.out$max&lt;-apply(tab.out, 1, max)
  for(i in names(tab.out)){
    tab.out[[paste(i, 'test', sep="_")]] &lt;- if_else(tab.out[[i]] &lt; tab.out$max,
                                                 paste0(i, "\\textsuperscript{*}"),
                                                 paste0(i))
  }
  
  #        X1       X2      max                X1_test                X2_test max_test
  #1 4.70e+01 4.67e+01 4.70e+01                     X1 X2\\textsuperscript{*}      max
  #2 4.72e+01 4.69e+01 4.72e+01                     X1 X2\\textsuperscript{*}      max
  #3 4.76e+01 4.77e+01 4.77e+01 X1\\textsuperscript{*}                     X2      max
  #4 2.73e+20 2.05e+20 2.73e+20                     X1 X2\\textsuperscript{*}      max
  </code></pre>