0

I'm using R Sweave and wanted to begin my document with showing a sample of my table. My problem is, that my table has 39 variables and many rows. For the rows it isn't a problem, I can take only a few ones using sample_n, but I need to habe all my variables visible. It would sadly not fit either on a landscape sheet. I'm using xtable to generate my table. I think the easier way would be to put so much variables as possible on the sheet, then begin with the rest under, and so on, until it is all displayed.

Here some minimalist exemple:

dat <- bind_cols(mtcars, mtcars, mtcars, mtcars)
a <- as.data.frame(dat) %>%
  sample_n(5)
print(xtable(a))

I've already know the longtable function, but it would only help me if I had too much rows, and not too much columns, isn't it? I'm still a little bit lost with having at the same time R and LaTeX on the same file...

GaryDe
  • 492
  • 1
  • 5
  • 17
  • Why making a latex table and not an R printing of the table? – F. Privé Jul 20 '17 at 19:41
  • Good point! Because 1) I use the whole document then xtable, and wanted to have the same output, but that wouldn't be such a problem 2) If I just print the layout is not so good. He align the items to the right and not the left, and it isn't easy enough to differencythe title line and the others. But it would be a nice solution if there was possible to improve the layout of the r printing instead of using LaTeX. I'll check if I find something pretty on the web. – GaryDe Jul 21 '17 at 08:20
  • Maybe try the function there: https://stackoverflow.com/a/44868837/6103040 – F. Privé Jul 21 '17 at 08:22
  • Thanks, it already helped a lot! I'm still facing two issues: the title row is still too hard to see, and I haven't achieve to not print the NA values (I wrote na.print="" in the print environment, but it seems not to be very usefull). – GaryDe Jul 21 '17 at 09:43

1 Answers1

0

An answer using my huxtable package. Create the table, then break it up by columns:

library(huxtable)
dat <- sample_n(as.data.frame(bind_cols(mtcars, mtcars, mtcars, mtcars)), 5)
ht <- as_hux(dat, add_colnames = TRUE)

# now format to taste:
bold(ht)[1,] <- TRUE

ht[,1:5] # first 5 columns. Will print as LaTeX within a Rmarkdown document
  • Thanks for the help, but I'm using R Sweave, not R Markdown, and the output is then not the one searched, because it apparently doesn't render the same way. – GaryDe Jul 27 '17 at 11:42
  • Maybe just call print_latex on the huxtable. –  Jul 27 '17 at 17:04
  • I obtain this result: [picture](http://i.imgur.com/7NtZc3L.png). Can't understand what I did false. – GaryDe Jul 31 '17 at 15:19