'Is there an automatic way to merge cells in R openxlsx?

The output of my data has a large number of results, and some grouping variables e.g. age. Does openxlsx have a way that I can automatically merge the grouping column together into a single, centred entry for each different value in the grouping column?

Col for Grouping Statistic
age Mean
age Median
age Mode
sex Female
sex Male

In the example above I'd want the cells with age and the cells with sex to become two merged cells with age and sex in.

I think I could automate it myself by finding the min and max row which each value appears on then merging those cells with mergeCells() but I'm hoping that there's an automatic method already implemented.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source