sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, 'Species'),
th(colspan = 2, 'Sepal'),
th(colspan = 2, 'Petal')
),
tr(
lapply(rep(c('Length', 'Width'), 2), th)
)
)
))
print(sketch)
并获取
<table class="display">
<thead>
<tr>
<th rowspan="2">Species</th>
<th colspan="2">Sepal</th>
<th colspan="2">Petal</th>
</tr>
<tr>
<th>Length</th>
<th>Width</th>
<th>Length</th>
<th>Width</th>
</tr>
</thead>
</table>
如果我有N列,有没有办法循环这两行?
<th colspan="2">Sepal</th>
<th colspan="2">Petal</th>
类似的东西:
lapply(c('Sepal', 'Petal'), th)
但我无法弄清楚如何放入“colspan=2
”部分。
非常感谢,