I'm trying to make a loop for a table that will be generated in 'xtable'.

This is what I did "manually" together is here:

**What I want to get**

```
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 %>%
  mutate(test1 = if_else(tab.out$X1 < tab.out$X2,
                         paste0(X1,"$^{*}$"),
                         paste0(X1)),
         test2 = if_else(tab.out$X2 < tab.out$X1,
                         paste0(X2,"\\textsuperscript{*}"),
                         paste0(X2)))%>%
  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{*}

```

I want to make a loop for n-columns using conditionals as seen below in the code (**My current ugly and error-prone fix**):

**Lo que obtuve ?**

```
tab.out = data.frame(X1, X2)
tab.out$max<-apply(tab.out, 1, max)
for(i in names(tab.out)){
  tab.out[[paste(i, 'test', sep="_")]] <- if_else(tab.out[[i]] < 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

```