Search code examples
rformatconditional-statementsformattable

R Color Every Other Row


Is there a way to create an R table (I want to eventually output it as a PNG). With every other row colored? All of the options I am seeing to color rows are based on the row value and the number of rows and row values will be dynamic so I can't do it that way.

Below is an example of what I want enter image description here


Solution

  • You can use theme_zebra from flextable

    library(flextable)
    ftab <- flextable(head(iris))
    theme_zebra(ftab)
    

    enter image description here