I use pander
to generate pandoc style tables, often I need to suppress repeated values of variables like this example:
ta <- data.frame(class=c(rep("C1" ,3), rep("C2", 6)),
name=rep(c("L", "V", "C"), each=3), num=rpois(9, 10))
pandoc.table(ta)
The output is
--------------------
class name num
------- ------ -----
C1 L 15
C1 L 11
C1 L 8
C2 V 7
C2 V 7
C2 V 5
C2 C 12
C2 C 9
C2 C 12
--------------------
and I would like
--------------------
class name num
------- ------ -----
C1 L 15
11
8
C2 V 7
7
5
C 12
9
12
--------------------
The problem is similar to this Removing Locally Repeated Values and as I use dplyr for data.frames a solution using mutate should be worth, I tried this but did not work:
mutate(ta, class=ifelse(lag(class,1) == class & !is.na(lag(class,1)), "", class ))
This seems like an open bug that will be corrected. In the meantime this workaround seems to do the job: