The group_tt() function can label groups of rows (i) or columns (j).
Rows
The i argument accepts a named list of integers. The numbers identify the positions where row group labels are to be inserted. The names includes the text that should be inserted:
dat <- mtcars[1:9, 1:8]tt(dat) |>group_tt(i =list("I like (fake) hamburgers"=3,"She prefers halloumi"=4,"They love tofu"=7))
mpg
cyl
disp
hp
drat
wt
qsec
vs
21
6
160
110
3.9
2.62
16.5
0
21
6
160
110
3.9
2.88
17
0
22.8
4
108
93
3.85
2.32
18.6
1
21.4
6
258
110
3.08
3.21
19.4
1
18.7
8
360
175
3.15
3.44
17
0
18.1
6
225
105
2.76
3.46
20.2
1
14.3
8
360
245
3.21
3.57
15.8
0
24.4
4
147
62
3.69
3.19
20
1
22.8
4
141
95
3.92
3.15
22.9
1
The numbers in the i list indicate that a label must be inserted at position # in the original table (without row groups). For example,
Calculating the location of rows can be cumbersome. Instead of doing this by hand, we can extract information from the table@group_index_i S4 slot in the table object. Please be aware, however, that slot names are subject to change without warning in future versions of tinytable.
The syntax for column groups is very similar, but we use the j argument instead. The named list specifies the labels to appear in column-spanning labels, and the values must be a vector of consecutive and non-overlapping integers that indicate which columns are associated to which labels: