Transposing an XTable in RMarkdown

Hi,

I have made a table in R Markdown using XTable. I'm having trouble transposing the table to landscape format because it does not fit on the page currently. Can anyone advise me on how to transposing this table

I have added my code below. First, I made a dataframe with the contents I want in my table

library(xtable)

variables <- c("Argentina Bond Flows", "Argentina Equity Flows", "Chile Bond Flows", "Chile Equity Flows", "Mexico Bond Flows",
               "Mexico Equity Flows", "Indonesia Bond Flows", "Indonesia Equity Flows", "Korea Bond Flows", "Korea Equity Flows",
               "Philippines Bond Flows", "Philippines Equity Flows", "Thailand Bond Flows", "Thailand Equity Flows", 
               "South Africa Bond Flows", "South Africa Equity Flows","United States S\\&P 500", "United States M1")

adf <- c("-4.3557","-6.4865","-3.4893","-3.3485","-2.6294","-5.511","-2.9238","-6.0305","-9.7081","-2.0444","-4.7619","-5.6108","-4.6314","-4.6218","-4.3337","-3.7213","2.6471"," 4.0174")
pp <- c("-6.9685","-9.3864","-6.7449","-5.6533","-6.0265","-9.4065","-6.531","-7.5043","-21.0764","-3.5716","-8.3505","-6.5574 ","-10.3266","-7.445","-8.9639","-6.3464","-11.1298","4.0512")

variables2 <- c("Argentina M1", "Argentina Equity Index", "Chile M1", "Chile Equity Index", "Mexico M1",
                "Mexico Equity Index", "Indonesia M1", "Indonesia Equity Index", "Korea M1", "Korea Equity Index",
                "Philippines M1", "Philippines Equity Index", "Thailand M1", "Thailand Equity Index", 
                "South Africa M1", "South Africa Equity Index","", "")

adf2 <- c("-6.9593","6.1785","3.6245","-2.2697","3.2417","2.4172","2.4237","2.0484","3.8211","-6.938","-6.9593","-7.7315","-6.9593","6.1785","-8.0415 ","2.5385","","")
pp2 <- c("-13.7725","4.8728","-11.0177","-9.3776","-14.3688 ","-2.2334","-13.1095","-8.8171","-11.1806","-9.8397","-13.7725","-9.4015","-2.6801","-11.8756","-10.681"," -9.6241","","")

unit_table <- data.frame(variables, adf, pp,variables2, adf2,pp2, stringsAsFactors = FALSE)
colnames(unit_table) <- c("Country Variable", "ADF", "PP","Country Variable", "ADF", "PP")

# Create a table using XTable

unit_table[9, "Country Variable"] <- paste0("BOLD", unit_table[9, "Country Variable"])

table <- xtable(unit_table, 
                caption = "Unit Root Test Results \\label{Table3}",
                # tabular.environment = "longtable",
                floating = TRUE,
                table.placement = 'H',
                include.rownames = FALSE,
                # scalebox = 0.3,
                comment = FALSE,
                caption.placement = 'top',
                align = "ll|l|l|l|l|l"
)

# Additional code added

bold.function <- function(x) gsub('BOLD(.*)', paste('\\\\textbf{\\1','}'),x)

comment <- list(pos = list(0))
comment$pos[[1]] <- c(nrow(unit_table))
comment$command <- c(paste("\\hline\n", 
                           "This table presents the results from the Augmented Dickey Fuller (ADF) and Phillips Perron (PP) tests. 
Note that certain variables have been transformed to satisfy stationarity requirements, either through first differencing or detrending. 
The critical values at the 1, 5 and 10 percent significance level are -2.58, -1.95 and -1.62 respectively
.\n", 
                           sep = ""))

print(table, add.to.row = comment, hline.after = c(-1, 0), sanitize.text.function = bold.function, comment = FALSE)

Any advice on how to transpose this table so it fits?

TIA

Could you edit the reproducible example, called a reprex with representative data?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.