buhtz
buhtz

Reputation: 12152

Convert a table into flextable in R

The question is about R and the flextable package.

This simple R-output

> table(mtcars["gear"])

 3  4  5 
15 12  5 

need to be converted to a flextable.

But when I use flextable() instead of table() each observeration is shown and not the frequency of the 3 possible gears.

It looks like this enter image description here

Upvotes: 0

Views: 2855

Answers (1)

guscht
guscht

Reputation: 893

You need to convert the output of table() into a data.frame and then you can display it with flextable. Flextable is only meant to display something, not to pivot it - as was mentioned in the comments. Try this:

flextable(data.frame(table(mtcars["gear"])))

enter image description here

Make sure to read the documentation of the packages you are using. ;)

Upvotes: 4

Related Questions