knitr package includes a handy kable() function that produces simple tables:
data(mtcars)knitr::kable( head(mtcars))
mpg
cyl
disp
hp
drat
wt
qsec
vs
am
gear
carb
Mazda RX4
21.0
6
160
110
3.90
2.620
16.46
0
1
4
4
Mazda RX4 Wag
21.0
6
160
110
3.90
2.875
17.02
0
1
4
4
Datsun 710
22.8
4
108
93
3.85
2.320
18.61
1
1
4
1
Hornet 4 Drive
21.4
6
258
110
3.08
3.215
19.44
1
0
3
1
Hornet Sportabout
18.7
8
360
175
3.15
3.440
17.02
0
0
3
2
Valiant
18.1
6
225
105
2.76
3.460
20.22
1
0
3
1
3 pander
pander package is a relatively simple to use package. It can produce well-formatted tables for the outputs of summary() function for the datasets and models:
library(pander)pander( summary(mtcars[, 1:4]) )
mpg
cyl
disp
hp
Min. :10.40
Min. :4.000
Min. : 71.1
Min. : 52.0
1st Qu.:15.43
1st Qu.:4.000
1st Qu.:120.8
1st Qu.: 96.5
Median :19.20
Median :6.000
Median :196.3
Median :123.0
Mean :20.09
Mean :6.188
Mean :230.7
Mean :146.7
3rd Qu.:22.80
3rd Qu.:8.000
3rd Qu.:326.0
3rd Qu.:180.0
Max. :33.90
Max. :8.000
Max. :472.0
Max. :335.0
model <-lm( mpg ~ cyl, data=mtcars ) # a simple lenear regressionpander( summary(model) )
Estimate
Std. Error
t value
Pr(>|t|)
(Intercept)
37.88
2.074
18.27
8.369e-18
cyl
-2.876
0.3224
-8.92
6.113e-10
Fitting linear model: mpg ~ cyl
Observations
Residual Std. Error
\(R^2\)
Adjusted \(R^2\)
32
3.206
0.7262
0.7171
4 DT
DT package can display matrices and data frames as tables and provides filtering and sorting. It is especially useful to display long tables that do not fit on a single page:
DT::datatable(data=mtcars)
5 kableExtra
kableExtra package extends functionality of the kable package.