Hello,
I need to specify the col.names in kable according to the number of rows from a table.
I was thinking about using if and ifelse to do it, but I can't reproduce what I want.
data2=datasets::chickwts
data2=data2 %>% mutate(over=weight>200)
tb1=data2 %>% filter(feed=="linseed") %>%group_by(over) %>% count() %>% spread(over,n)
jkl=ncol(tb1)
if (jkl==1) {
kable(tb1,col.names = c("Blue")) %>%
} else {
kable(tb1,col.names = c("Blue","Black")) %>% }
kable_styling(full_width = TRUE)
The issue is I can't process two kinds of tables. One with 1 column, another with 2.
I wrote this because I need to be able to change only the filer condition and repeat the code without worrying about it.
This is my first thread on this forum section. I hope I posted tall you need in order to understand my case.
Thanks for your time and interest.
Good luck