r - Generate a pandoc table without repeated values -
i use pander
generate pandoc style tables, need suppress repeated values of variables 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 like
-------------------- class name num ------- ------ ----- c1 l 15 11 8 c2 v 7 7 5 c 12 9 12 --------------------
the problem similar removing locally repeated values , use dplyr data.frames solution using mutate should worth, tried did not work:
mutate(ta, class=ifelse(lag(class,1) == class & !is.na(lag(class,1)), "", class ))
this seems open bug corrected. in meantime workaround seems job:
mutate(ta, class=ifelse(levels(class)[lag(class,1)] == class & !is.na(levels(class)[lag(class,1)]), "", class)) class name num 1 1 l 8 2 l 14 3 l 12 4 2 v 11 5 v 7 6 v 15 7 c 16 8 c 8 9 c 9
Comments
Post a Comment