0

也作为问题发布在github

使用 后group_by,无法通过digits=orround=参数正确输出带有 pandoc 的表格。

从链条中取出group_by,pandoc 可以很好地显示表格。加上group_by浮点数的 in 和小数位数是大显示的方式。

# test dataframe
dat <- data.frame(matrix(rnorm(10 * 10), 10))
group <- rbinom(10,20,.1)
df1 <- cbind(group, dat)

library(pander)

pander(df1, digits = 2, keep.line.breaks = TRUE, split.table = Inf,
       caption = "Not Grouped, correct format") 

library(dplyr)
df2 <- df1 %>% 
      group_by(group) 

pander(df2, digits = 2, keep.line.breaks = TRUE, split.table = Inf,
       caption = "Grouped, incorrect format") 

有没有解决的办法?

4

1 回答 1

1

作为一种解决方法,您可以将df2(类tbl_df)对象转换为data.frame对象。

pander(as.data.frame(df2), digits = 2, keep.line.breaks = TRUE, split.table = Inf)

结果:

-----------------------------------------------------------------------
 group    X1    X2    X3    X4     X5    X6    X7     X8     X9    X10 
------- ------ ----- ----- ----- ------ ----- ----- ------ ------ -----
   0    -0.55  -0.13 -0.71 -1.3  -0.096 0.49  0.73  -0.53   0.17  -0.44

   2     -1.5   1.4  -2.1  0.96   -0.2  -0.36 0.33   0.2    0.67  -0.27

   1     -2.3  -0.98 -1.5   1.1   0.87  -0.54  1.2  -0.24   0.31  -0.76

   1     0.24  0.086 -0.78 0.39  -0.17  -0.2  -1.5   -1.1   -1.3  -0.72

   0     0.2   -1.2  0.27   2.1   0.73   1.8  -0.12 -0.45   0.07  -0.29

   1    0.022  0.084 -0.41 0.32  -0.023 0.38  0.57  -0.16  0.0011 -0.76

   2     0.99   0.7  -0.32 -0.25 -0.17  -0.68 -0.59  0.29   0.77  -0.12

   3     -1.3  -1.6  -0.14 0.49   0.61   1.2  0.14  -0.087  -1.2  -0.95

   0    -0.073 -0.86   2   -0.87  0.51  -1.3  -0.94 0.022   0.6   0.68 

   3     1.8   -0.81 -0.4  0.72   2.1   0.19  0.086  1.7    0.19  -0.49
-----------------------------------------------------------------------
于 2016-06-07T07:56:49.127 回答