Don't print row numbers on a transposed data frame (dplyr / flextable)

This is following up on a previous topic I posted: In that one I learned how to add the column names to my transposed data frame using dplyr, like so:

library(flextable)
library(dplyr)
iris %>%
    head() %>%
    t() %>% 
    as.data.frame() %>% 
    add_rownames() %>% 
    flextable()

Perhaps the keen eyes here might anticipate my follow-up: how do I hide/ set to blank the row numbers running along the columns of my transposed data frame? I'm doing the data manipulation in dplyr and formatting it to go to Word via flextable so are either of those two packages helpful for this?

Thanks very much.

I think the problem with your example is that you need unique values for colnames, take a look at this code

library(flextable)
library(dplyr)
iris %>%
  group_by(Species) %>% 
  summarise_all(mean) %>%
  t() %>%
  as.data.frame() %>% 
  add_rownames() %>%
  mutate_all(as.character) %>% 
  setNames(as.character(.[1,])) %>% 
  tail(-1) %>% 
  flextable()

image

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.