
Create a linesep for kable
linesep.RdCreate a linesep for kable
Examples
temp = iris[sample(seq_len(nrow(iris)), 10),]
kable(temp, linesep = linesep(diff(as.integer(temp[["Species"]])) != 0))
#> \begin{table}
#> \centering
#> \begin{tabular}{lrrrrl}
#> \toprule
#> & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species\\
#> \midrule
#> 13 & 4.8 & 3.0 & 1.4 & 0.1 & setosa\\
#> 39 & 4.4 & 3.0 & 1.3 & 0.2 & setosa\\
#> 3 & 4.7 & 3.2 & 1.3 & 0.2 & setosa\\
#> 7 & 4.6 & 3.4 & 1.4 & 0.3 & setosa\\
#> 12 & 4.8 & 3.4 & 1.6 & 0.2 & setosa\\
#> \midrule
#> 149 & 6.2 & 3.4 & 5.4 & 2.3 & virginica\\
#> 139 & 6.0 & 3.0 & 4.8 & 1.8 & virginica\\
#> \midrule
#> 42 & 4.5 & 2.3 & 1.3 & 0.3 & setosa\\
#> 40 & 5.1 & 3.4 & 1.5 & 0.2 & setosa\\
#> \midrule
#> 113 & 6.8 & 3.0 & 5.5 & 2.1 & virginica\\
#> \bottomrule
#> \end{tabular}
#> \end{table}
kable(temp, linesep = linesep(temp[["Species"]][-1] != temp[["Species"]][-nrow(temp)]))
#> \begin{table}
#> \centering
#> \begin{tabular}{lrrrrl}
#> \toprule
#> & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species\\
#> \midrule
#> 13 & 4.8 & 3.0 & 1.4 & 0.1 & setosa\\
#> 39 & 4.4 & 3.0 & 1.3 & 0.2 & setosa\\
#> 3 & 4.7 & 3.2 & 1.3 & 0.2 & setosa\\
#> 7 & 4.6 & 3.4 & 1.4 & 0.3 & setosa\\
#> 12 & 4.8 & 3.4 & 1.6 & 0.2 & setosa\\
#> \midrule
#> 149 & 6.2 & 3.4 & 5.4 & 2.3 & virginica\\
#> 139 & 6.0 & 3.0 & 4.8 & 1.8 & virginica\\
#> \midrule
#> 42 & 4.5 & 2.3 & 1.3 & 0.3 & setosa\\
#> 40 & 5.1 & 3.4 & 1.5 & 0.2 & setosa\\
#> \midrule
#> 113 & 6.8 & 3.0 & 5.5 & 2.1 & virginica\\
#> \bottomrule
#> \end{tabular}
#> \end{table}
temp = temp[order(temp[["Species"]]), ]
kable(temp, linesep = linesep(cumsum(table(temp[["Species"]]))))
#> \begin{table}
#> \centering
#> \begin{tabular}{lrrrrl}
#> \toprule
#> & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species\\
#> \midrule
#> 13 & 4.8 & 3.0 & 1.4 & 0.1 & setosa\\
#> 39 & 4.4 & 3.0 & 1.3 & 0.2 & setosa\\
#> 3 & 4.7 & 3.2 & 1.3 & 0.2 & setosa\\
#> 7 & 4.6 & 3.4 & 1.4 & 0.3 & setosa\\
#> 12 & 4.8 & 3.4 & 1.6 & 0.2 & setosa\\
#> 42 & 4.5 & 2.3 & 1.3 & 0.3 & setosa\\
#> 40 & 5.1 & 3.4 & 1.5 & 0.2 & setosa\\
#> \midrule
#> 149 & 6.2 & 3.4 & 5.4 & 2.3 & virginica\\
#> 139 & 6.0 & 3.0 & 4.8 & 1.8 & virginica\\
#> 113 & 6.8 & 3.0 & 5.5 & 2.1 & virginica\\
#> \bottomrule
#> \end{tabular}
#> \end{table}