我正在使用Rmarkdown生成报告,需要能够呈现为Word格式。我希望能够重现这个表格格式:
我尝试使用flextable
实现,但没有取得任何进展。我已经阅读了flextable
网站,并找到了一种使用组合来合并行的方法,但不知道如何对列进行分组。
as_grouped_data()
函数可以事先创建组,但我能否将这些组用作列标题呢?
我的数据的一个简单示例:
df = structure(list(Athlete = structure(c(1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 2L), .Label = c("Athlete 1", "Athlete 2"), class = "factor"),
Time = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L), .Label = c("1", "2", "3"), class = "factor"), Measure = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Distance",
"Speed"), class = "factor"), Value = c(4.02, 11.5, 19.82,
3.03, 9.67, 17.9, 6.5, 8.08, 8.47, 5.3, 7.64, 8.67)), row.names = c(NA,
-12L), class = "data.frame")
# Create table
myft = flextable(df)
# Merge athlete column
myft = merge_v(myft, j=c("Time", "Athlete"))
myft
我被卡在这里,不确定如何将这些分组从行标题转换为列标题。