How can I make a collapse with glue package using RMarkdown?

前端 未结 1 1334
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 06:52

I\'ve been trying to automate the results of some df table in latex using the glue and stargazer packages, but I haven\'t had any results (what I want is for the meaning \"^{*}\

相关标签:
1条回答
  • 2021-01-25 07:32

    I achieved this using the paste0 function as mentioned here and on the recommendation of @stefan but now I would like to automate the same function for n-columns

    library(dplyr)
    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)
    
    colnames(n.tab) = c("Parámetros", "Lag 1", "Lag 2")
    print(xtable::xtable(n.tab, 
                         header = F, 
                         caption = "asdasdasdasd",
                         label="table:tb1",
                         caption.placement = "top",
                         align="llcc"),
          hline.after = c(-1,0), 
          include.rownames=FALSE, 
          include.colnames = TRUE,
          add.to.row = list(pos = list(nrow(n.tab)),
                            command = paste("\\hline \n",
                                "\\multicolumn{3}{l}{\\footnotesize{$^{*}$Indica el orden de retraso seleccionado}} \\\\",
                                "\\multicolumn{3}{l}{\\footnotesize{\\textit{Elaboración: Los autores}}}",
                                sep = "")), comment=FALSE,
          sanitize.text.function = function(x){x})
    

    0 讨论(0)
提交回复
热议问题