Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. ---
  2. title: "Long table test"
  3. output: pdf_document
  4. ---
  5.  
  6. Here is a table:
  7.  
  8. ```{r setup}
  9. library (data.table)
  10. library (pander)
  11.  
  12. set.seed(1984)
  13. longString <- "description string"
  14. dt <- data.table(id=c(1:3),description=rep(longString,3),value=rnorm(3,mean=10000,sd=1))
  15. ```
  16.  
  17. ```{r pander-table}
  18. panderOptions('round',2)
  19. panderOptions('digits',2)
  20. panderOptions('keep.trailing.zeros',TRUE)
  21. pander(dt, split.cell = 80, split.table = Inf)
  22. ```
  23.  
  24. -------------------------------
  25. id description value
  26. ---- ------------------ -------
  27. 1 description string 10000
  28.  
  29. 2 description string 10000
  30.  
  31. 3 description string 10001
  32. -------------------------------
  33.  
  34. ----------------------------------
  35. id description value
  36. ---- ------------------ ----------
  37. 1 description string 10000.41
  38.  
  39. 2 description string 9999.68
  40.  
  41. 3 description string 10000.64
  42. ----------------------------------
  43.  
  44. > format(c( 10000.41, 9999.68, 10000.64 ), digits=2)
  45. [1] "10000" "10000" "10001"
  46.  
  47. library (data.table)
  48. library(magrittr)
  49. library (pander)
  50.  
  51. set.seed(1984)
  52. longString <- "description string"
  53. dt <- data.table(id = c(1:3),
  54. description = rep(longString, 3),
  55. value = rnorm(3, mean = 10000, sd = 1))
  56.  
  57. pander(
  58. x = dt %>%
  59. mutate(value = value %>% round(2) %>% as.character()),
  60. split.cell = 80,
  61. split.table = Inf,
  62. justify = "ccr"
  63. )
  64.  
  65. ------------------------------------
  66. id description value
  67. ---- -------------------- ----------
  68. 1 description string 10000.41
  69.  
  70. 2 description string 9999.68
  71.  
  72. 3 description string 10000.64
  73. ------------------------------------
Add Comment
Please, Sign In to add comment