
Replace kable with some useful
kable_units.Rd
Replace kable with some useful
Examples
temp = head(iris)[c(5, 1:4)]
temp[["Species"]] = as.character(temp[["Species"]])
kable_units(head(temp))
#>
#> \begin{tabular}{lrrrr}
#> \toprule
#> \textbf{Species} & \textbf{Sepal.Length} & \textbf{Sepal.Width} & \textbf{Petal.Length} & \textbf{Petal.Width}\\
#> \midrule
#> setosa & 5.1 & 3.5 & 1.4 & 0.2\\
#> setosa & 4.9 & 3.0 & 1.4 & 0.2\\
#> setosa & 4.7 & 3.2 & 1.3 & 0.2\\
#> setosa & 4.6 & 3.1 & 1.5 & 0.2\\
#> setosa & 5.0 & 3.6 & 1.4 & 0.2\\
#> setosa & 5.4 & 3.9 & 1.7 & 0.4\\
#> \bottomrule
#> \end{tabular}
temp = rbind(temp, c(Species = "mean", as.list(colMeans(temp[-1]))))
kable_units(temp, -1)
#>
#> \begin{tabular}{lrrrr}
#> \toprule
#> \textbf{Species} & \textbf{Sepal.Length} & \textbf{Sepal.Width} & \textbf{Petal.Length} & \textbf{Petal.Width}\\
#> \midrule
#> setosa & 5.10 & 3.500000 & 1.40 & 0.2000000\\
#> setosa & 4.90 & 3.000000 & 1.40 & 0.2000000\\
#> setosa & 4.70 & 3.200000 & 1.30 & 0.2000000\\
#> setosa & 4.60 & 3.100000 & 1.50 & 0.2000000\\
#> setosa & 5.00 & 3.600000 & 1.40 & 0.2000000\\
#> setosa & 5.40 & 3.900000 & 1.70 & 0.4000000\\
#> \midrule
#> mean & 4.95 & 3.383333 & 1.45 & 0.2333333\\
#> \bottomrule
#> \end{tabular}
temp = rbind(temp, c("units", "mm", "mm", "mm", "mm"))
kable_units(temp, -1)
#>
#> \begin{tabular}{lrrrr}
#> \toprule
#> \textbf{Species} & \textbf{Sepal.Length} & \textbf{Sepal.Width} & \textbf{Petal.Length} & \textbf{Petal.Width}\\
#> \midrule
#> setosa & 5.1 & 3.5 & 1.4 & 0.2\\
#> setosa & 4.9 & 3 & 1.4 & 0.2\\
#> setosa & 4.7 & 3.2 & 1.3 & 0.2\\
#> setosa & 4.6 & 3.1 & 1.5 & 0.2\\
#> setosa & 5 & 3.6 & 1.4 & 0.2\\
#> setosa & 5.4 & 3.9 & 1.7 & 0.4\\
#> \midrule
#> mean & 4.95 & 3.38333333333333 & 1.45 & 0.233333333333333\\
#> \midrule\\
#> \em{units} & \em{mm} & \em{mm} & \em{mm} & \em{mm}\\
#> \bottomrule
#> \end{tabular}