anderwyang
anderwyang

Reputation: 2451

In r/formattable, how to adjust column format not include `total` row

In r/formattable, how to adjust column format not include total row ?

library(formattable)
df <- data.frame(category=c('a','b','total'),value=c(1,2,3))
formattable(df,list(
  category[-3,] = formatter("span",
                       style = x ~ style(color = "red")
  )
))

Upvotes: 2

Views: 225

Answers (1)

akrun
akrun

Reputation: 887951

We may use ifelse

library(formattable)
formattable(df,list(
  category = formatter("span",
                            style = x ~ ifelse(x != 'total', 
       style(color = "red"), x)
  )
))

enter image description here


If it is for the value column based on the 'category'

formattable(df,list(
  value = formatter("span",
                            style = x ~ ifelse(df$category != 
       'total', style(color = "red"), x)
  )
))

Upvotes: 2

Related Questions