flextable -- print row names of transposed data frame

I am using flextable to format data frame output. I would like to transpose some of them for display, but can't figure how to get the row names to show in the output. Any ideas?

I am happy using another package -- my thought was to use flextable because I want to render directly to MS Word and from what I understand this is the best package for that.


# Transposed data frame
iris_head <- as.data.frame(t(head(iris)))

# I would like to display the row names
# in the column of the output


1 Like

You can use add_rownames()

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

You can do a similar thing for the column names but, with iris dataset is not possible because of the duplicated species name


Thanks so much -- much nicer transpose operation too.

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.