R Markdown

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(broom)
df = data.frame(y = rnorm(1000),
           x = sample(letters, size = 1000, 
                      replace = TRUE),
           stringsAsFactors = FALSE)
df$y[ sample(1:1000, size = 20)] = NA
summ = df %>% 
  group_by(x) %>% 
  summarize(mean = mean(y, na.rm = TRUE),
            sd = sd(y, na.rm = TRUE),
            not_missing = sum(!is.na(y)),
            n =n())
summ = summ %>% 
  filter(x %in% letters[1:5])
library(knitr)
library(kableExtra)
summ$z = "Hey I am a very long string and I  want to be wrapped"
knitr::kable(summ, digits = 2)
x mean sd not_missing n z
a -0.02 1.24 39 40 Hey I am a very long string and I want to be wrapped
b -0.33 1.10 29 31 Hey I am a very long string and I want to be wrapped
c 0.29 1.08 35 36 Hey I am a very long string and I want to be wrapped
d 0.20 0.86 44 45 Hey I am a very long string and I want to be wrapped
e 0.23 1.04 45 46 Hey I am a very long string and I want to be wrapped
knitr::kable(summ, 
             format = "html") %>% 
  kable_styling()
x mean sd not_missing n z
a -0.0219698 1.2376947 39 40 Hey I am a very long string and I want to be wrapped
b -0.3262498 1.0994004 29 31 Hey I am a very long string and I want to be wrapped
c 0.2918926 1.0790135 35 36 Hey I am a very long string and I want to be wrapped
d 0.1950587 0.8612378 44 45 Hey I am a very long string and I want to be wrapped
e 0.2300216 1.0368087 45 46 Hey I am a very long string and I want to be wrapped
grouped = diff(as.numeric(factor(summ$x)))
grouped = which(grouped > 0)
knitr::kable(df, format = "html") %>% 
  kable_styling() %>% 
  group_rows("Day 0", 1, grouped[1]) %>% 
  group_rows("Day 1", grouped[1] + 1, grouped[2]) %>% 
  group_rows("Day 2", grouped[2] + 1, grouped[3]) %>% 
  group_rows("Day 3", grouped[3] + 1, grouped[4]) 
y x
Day 0
-1.3194974 e
Day 1
-0.2482841 e
Day 2
-0.0328160 t
Day 3
0.0881583 y
-1.0096502 t
-0.7080342 p
-1.5316192 y
-0.3637600 f
1.1947899 d
0.0817948 b
-1.0123747 j
0.7842761 h
0.3549191 w
0.1963179 e
-2.3308369 a
0.4104342 t
0.8179690 j
-1.2551900 l
0.7461988 k
1.1126600 r
0.1316018 w
-0.6234239 y
-1.4179176 p
1.1893280 s
0.6660282 g
-0.9455917 k
1.0527242 f
0.3801456 o
0.9197737 o
-2.1857699 n
0.9380617 h
0.3940185 z
-0.1957498 c
0.4243652 j
-1.1338642 f
1.6400250 w
-0.2369628 k
NA r
0.5315766 l
-0.5816774 m
0.7350057 w
0.4124350 v
-1.2188912 h
-0.5085232 h
-0.3303636 a
-0.1760894 f
1.5131574 o
0.9922325 f
-0.1513467 n
-0.0780309 l
1.3677655 l
-0.5871929 t
-1.2783634 b
-0.7589307 r
0.4994525 z
-0.4762406 h
-2.7609239 q
0.9044450 w
0.0926690 n
0.4831711 c
0.7761747 o
0.3451252 h
0.3419709 u
1.7788914 l
-2.6366291 b
0.4667386 c
1.5517120 y
-0.2369663 d
-0.5515348 q
0.8105068 d
-0.1215769 m
-0.0771015 y
-0.1029987 n
1.0700353 k
0.2724840 a
0.5370411 a
0.5536722 p
1.0490669 y
-1.0629727 k
0.7761862 l
0.7499620 e
NA e
0.7618572 y
0.1078770 o
-0.3622605 c
-0.6179908 k
0.9439245 t
-0.7477240 m
0.2665851 z
0.8855872 m
1.3302924 o
-0.8799939 a
1.6175387 z
1.3225006 x
0.3286766 t
-1.5094784 p
-1.1820404 o
-1.1234449 w
-0.5480622 p
1.5589626 l
1.2462520 u
0.3761902 z
-0.2906812 q
-2.8718149 a
-1.2769407 k
-0.4267725 m
-0.6509642 i
-0.9133981 j
0.6482541 f
2.3456430 c
-1.5875568 x
0.4402977 q
0.1092883 h
-0.4971827 z
1.1487660 w
-0.5587169 f
0.8312679 i
1.9995996 v
-0.4536310 e
1.5380138 i
0.6574432 n
0.7103365 f
-0.1382898 k
-0.2568239 g
0.8184314 x
0.1533164 z
-0.3192782 p
1.3111490 j
0.9131330 d
0.6408271 c
2.2612083 z
0.8054334 s
-0.3872214 g
0.1363975 m
-0.3838983 m
0.5540047 o
-0.4740907 r
-2.8566356 o
-0.9284544 d
-0.2908224 c
1.1590074 n
-0.5840786 k
-0.4084720 b
0.2136901 t
1.2664545 l
1.5218922 j
1.7295655 z
0.6426905 f
1.0060167 m
-0.3397162 h
-0.8736104 z
-0.1388129 k
-0.4218682 s
-0.6960611 a
0.6105396 c
-0.6565066 r
0.2151003 d
-0.7473768 s
-0.5457621 w
0.3481902 o
-0.9920993 i
-0.9767556 i
1.3349879 c
-0.5975288 d
-0.9153760 b
2.1647509 d
0.1855865 x
-0.0457130 p
1.6917610 v
-1.2508424 i
0.2422270 g
1.0855286 n
0.0300120 b
1.1115300 u
-1.1641016 o
0.7981902 q
0.6728163 z
-0.5777988 n
0.6644164 h
-0.0313534 r
0.3476659 c
-0.9483526 b
0.8788715 j
-0.1040529 x
-0.0944812 i
-1.0423869 u
-1.3232979 a
0.0758090 j
0.0086267 r
0.9876716 c
-0.2314256 k
-1.4088002 t
1.7748215 w
0.2741465 i
0.5492504 c
-0.9564972 b
-0.2262652 y
-0.2948797 k
1.9473163 x
-0.8795859 e
1.3313651 b
0.5117841 u
-0.3549283 c
0.4270718 l
0.7211743 j
0.3384539 g
-0.1235535 j
-0.0906997 s
0.0520352 i
0.2914972 n
0.7332213 b
-0.7046478 f
-0.0776950 y
0.6382083 f
0.3140361 m
-0.8863844 t
0.4692220 y
0.2243981 q
-0.3218103 j
-0.6211252 h
1.3252879 x
0.5528426 z
0.5330153 n
1.0746394 g
-0.0361836 c
-1.1591865 z
1.6713171 j
-0.3616551 z
0.2836954 u
0.7669503 v
-0.7163045 i
0.6973788 v
-2.5550537 w
-1.5484680 c
-1.0784719 u
0.3709643 l
2.1270709 k
2.7264679 v
0.1014072 k
0.6241052 z
0.1342325 n
-0.1281968 q
-2.8974674 a
0.9957534 d
1.3147234 y
-1.2440620 p
1.2674014 z
-0.0499807 t
-0.0120756 q
-1.0480239 g
-0.5065923 e
-0.3219769 y
-0.9193937 r
-1.1077398 d
1.3993238 r
-0.9433647 q
3.1892794 c
0.8730686 p
1.9832240 k
-0.5865531 l
0.5739673 r
-0.8341547 q
0.0091966 s
0.3802161 l
-0.9853827 m
1.7015674 a
-0.8811566 l
-0.6958861 e
0.9618142 i
-0.8404840 k
-0.2156711 s
0.6777433 j
-0.2374713 a
-0.1293472 h
0.2154820 x
-0.4715137 s
-0.2310335 j
0.5120504 h
0.2598027 w
0.0515746 q
-0.9707007 g
0.8958823 h
1.4160122 t
-0.4985726 e
0.9612369 w
0.5883601 a
-0.5034569 b
-0.2906555 q
-0.5154129 b
2.4797445 t
1.0741984 e
0.7026282 x
-0.9288479 l
-0.1240945 r
0.4865004 m
-0.1723561 s
-0.3866677 v
-1.2001313 m
1.3991639 e
0.6825919 w
-2.0911289 g
1.4030064 g
-2.4210205 n
-0.4594054 h
1.2256640 a
1.7029910 e
0.8064844 i
0.6280138 d
0.6348573 x
-1.4053398 x
-0.1138550 p
-0.4465313 f
-0.1275800 w
-0.0834567 g
0.5073913 e
0.0117032 u
-0.0418200 v
0.4201402 w
-0.4562784 d
-0.2586239 i
-0.4520852 d
0.1614393 i
1.6376758 b
-0.9380333 f
-0.9124089 o
-0.0937310 i
-0.0542671 p
-0.5139394 d
0.1426488 d
1.1952579 g
0.2775000 d
-1.8406402 k
0.7382162 x
-1.0967342 p
1.9952128 o
-1.0524930 p
0.5069871 p
0.3695917 i
-0.7593308 y
0.2827962 u
-0.0164200 n
1.0643016 w
-0.3447455 f
-0.3674921 w
0.0910717 b
-0.4238415 p
-0.9465296 f
-0.7464648 j
1.3167223 p
1.6018459 c
-1.0757968 y
-0.3638925 t
0.5726359 w
-0.4550963 z
-0.1757797 j
1.6703133 q
0.1926793 t
0.3444165 q
-0.1348431 i
1.5921127 a
-0.8491236 c
-0.4659318 a
0.2178366 t
-0.3203963 n
1.0146565 i
-1.1362048 t
0.9445600 r
1.5003720 w
0.9574407 e
-0.2237102 t
-1.5697876 c
-0.9828865 m
-0.5524138 y
0.6581304 s
1.8100656 x
0.0850580 x
-1.4644460 w
2.8643052 u
0.6069676 c
-0.3214444 v
0.1069770 r
0.6517611 h
2.3810837 i
-0.1091126 s
0.2790654 i
-0.8136305 q
-0.0298177 j
-1.2995027 j
0.6373658 y
-0.5393815 a
-0.9625224 r
-0.2531466 x
0.8027078 h
0.1779700 x
-0.7840319 j
-2.6970030 j
0.0472269 p
0.4241261 e
-0.1961192 g
0.2398037 v
-0.4316930 x
-0.0145047 x
-0.3279975 h
2.1504098 m
-0.9193302 a
-0.0155852 j
-0.0344451 d
-1.3093814 f
-1.4513502 n
0.5912666 t
-1.5605795 u
0.3176515 n
-1.7247300 x
-0.3049680 b
0.3004064 n
-1.7110686 j
0.1115217 r
-0.6160671 z
-1.2739023 u
-0.8705424 h
-0.7832992 e
0.4306287 p
-0.3029826 t
0.4798001 h
-1.2589072 q
-0.1848250 y
-0.9666620 w
0.5026266 e
NA c
0.6910529 v
-0.0757575 j
-0.0457470 c
-1.2631815 b
-0.7294485 m
NA b
-0.2411117 o
0.2334802 p
0.5580240 h
NA u
-0.1789789 g
-1.7626052 b
0.6693324 p
0.4268282 g
1.8133123 m
0.6485915 q
-0.1910342 m
1.0744434 r
-0.9690473 w
0.4589289 v
-0.4431514 m
-0.3347226 d
-0.9775003 i
1.8656305 g
1.4716121 i
0.7196124 a
-0.7335206 w
0.5055377 k
-1.4795726 w
-0.6877745 a
-0.5557325 m
0.3867626 z
0.6940711 g
0.8808546 n
0.8770789 g
-1.0006483 r
-0.2569621 q
0.2786013 z
-0.6395880 q
-1.3445423 d
-0.8687230 e
-0.4256268 r
1.3238882 b
-0.2215182 a
1.1866773 a
0.9513723 v
0.9670220 h
0.4714619 v
-0.6370385 l
0.7590580 z
-1.3405155 v
0.9002998 x
0.2371987 h
-1.8410781 r
-0.8169740 h
0.3860238 t
-0.1331440 q
-0.3661803 b
-1.4437359 i
-0.3156785 c
-0.3239360 y
-0.7345708 i
0.8332911 q
-0.2098742 a
-1.0825077 y
1.3054994 t
-0.0777680 j
-1.0403395 n
1.9421340 a
-0.1344944 g
-0.3174808 z
-0.9145361 i
0.6544527 m
-0.0905913 i
0.4185166 d
0.9106713 p
0.0897007 o
0.5087991 q
1.5672526 o
1.6437433 d
0.3187442 n
-0.1878029 d
-0.3651392 l
-0.7709701 g
0.5977154 d
1.8962055 i
0.0358647 e
1.1862668 s
2.4506666 s
-1.3604754 h
0.2935033 u
-0.0854697 j
1.3906427 e
-1.0248826 t
-0.1883548 t
-0.4101985 q
-0.4519161 y
-0.2966724 l
0.8297455 s
1.1395331 w
0.8947330 m
1.8839466 t
-0.1149333 f
1.2673091 a
-1.1530311 j
-0.2233338 b
0.9095875 i
-1.4407847 j
-0.5513942 a
-1.3440552 o
2.0711485 y
0.7984474 k
-0.1170470 r
-1.7596660 o
1.1107121 q
-0.1144209 l
0.4267495 u
0.5262296 o
-1.6450158 n
-0.9824059 a
0.0598998 y
-2.2787114 i
0.3500158 n
0.3796992 s
-0.7934600 l
0.1079459 e
2.6786974 b
-0.5389834 a
-0.5489477 e
1.6884039 l
-1.4582965 f
-0.5850748 h
-0.3365188 r
0.6177396 d
0.3891931 i
-1.1796939 z
1.1031443 j
1.3946993 e
-1.5032474 g
-1.0710424 g
-0.7718589 b
-0.0439118 s
0.6238700 t
-0.7315622 b
1.0212728 u
-0.6345272 u
0.2667742 s
-0.1510532 s
0.4750563 f
-0.4228447 z
0.1878859 d
-0.9257603 g
1.5689663 y
-1.1401181 t
-2.6380395 g
1.3891081 x
-0.7161184 k
-1.1418045 m
0.7480868 v
-0.7691223 f
0.1174700 h
-0.5586000 n
0.6429446 u
NA u
-0.1225689 p
-0.1805417 i
-0.1195143 h
2.1849939 e
1.6402878 o
-1.0383010 d
0.3909710 x
-0.0491223 j
0.0270806 k
-0.7276596 x
1.5357828 y
NA x
-1.3121218 w
0.0011278 f
0.6141947 o
-0.3732146 h
0.8909349 l
0.9352404 e
-0.3892360 m
-0.6240726 d
-0.3421386 u
-0.1683657 e
0.2661721 g
-1.1358757 s
-1.0686109 r
-1.7494991 e
0.4642034 x
1.7996822 a
-0.1464691 q
-0.8755987 d
-0.0802422 o
1.1926624 e
0.0632598 b
-0.9562520 v
-0.5692510 o
-1.4942178 c
1.4368266 v
0.3027981 j
0.1526381 y
1.6598314 m
-0.0190970 a
0.4284558 w
-0.4373817 x
0.0887258 d
-0.0798818 f
0.6066276 a
-0.6667404 t
-0.5035777 f
-0.3476978 d
2.1674640 n
0.3471650 j
0.9277840 u
-1.3525733 t
0.6626729 p
1.2000698 z
-1.7028923 n
-0.1177176 v
0.7250738 s
-0.3754220 z
-1.0875910 t
0.1114676 d
-1.0017071 t
-0.3679898 l
1.3325469 z
0.8934275 f
-0.0131289 z
1.3020915 l
-0.4656077 l
0.5326828 q
-0.1096052 k
-0.1262497 r
1.8223822 r
-0.3489576 r
1.5017577 h
-0.7874422 h
1.0522373 p
0.3829852 e
-0.3862593 b
-0.2676728 u
2.0958154 i
-0.4913718 w
NA l
0.6597140 e
-0.8172221 r
1.2506146 v
0.7849518 i
-0.6149660 y
-0.3819662 o
-1.7111425 j
0.6452892 v
-0.8142881 o
-2.5998710 r
1.0731013 i
0.2247405 t
-0.4889566 z
-0.3436653 x
-1.7441674 v
-1.4447884 z
-1.5249758 q
-2.8759735 t
-1.3336218 y
-0.1196341 h
0.0622808 x
-1.6570419 u
0.3369145 x
-2.6404162 z
-0.8893658 n
-1.1418213 r
-0.9593791 g
-1.6563800 i
0.0375956 i
-0.4427251 g
0.0675721 r
-0.9297200 y
-1.1497960 e
-0.5967873 l
0.9932752 j
-1.9270503 o
0.4837467 i
-0.4403315 e
NA k
0.7549015 o
-0.3849097 p
0.3967127 h
0.5458714 t
0.0728662 l
0.9769038 q
NA w
-0.5007700 l
-0.0178599 g
0.6819270 m
0.3769248 o
1.3478958 k
-0.2567447 a
0.3832747 l
1.3354215 x
2.4609405 n
-0.2903600 r
-0.0976634 s
-0.6033972 o
0.0662234 x
1.5624751 f
-0.0041731 w
-0.4260488 c
NA u
-0.7035880 f
1.3119331 j
-0.1696351 h
0.3108192 u
-0.2178664 e
-0.9206206 u
0.7708294 r
1.2758763 o
-0.0735309 j
0.0679384 r
0.5719987 r
-0.4224722 f
0.4000033 a
-0.7929064 c
0.1161708 g
0.2369684 o
0.0456266 x
-0.4267023 v
-0.0889202 a
-1.1358463 r
0.3495813 s
2.6893535 y
-1.5348695 l
-0.1860950 d
-1.2314888 s
0.0900313 o
-0.3111081 h
1.7756567 c
-0.5989778 x
0.4803368 c
0.3199721 d
-0.2974709 r
NA a
0.3334880 n
-1.5962545 j
-0.3171453 p
0.6155157 o
-0.5280378 e
1.0178527 k
0.6295598 k
-0.2310603 w
0.7821445 c
-0.8356717 b
-1.5268898 o
-0.4813536 t
-1.1879027 h
1.6420328 i
-0.9386925 p
-1.5923320 t
NA n
0.6167003 s
-0.2754452 h
0.1474468 d
-0.0488599 l
-0.1263310 h
-0.1663663 w
0.5384349 e
-0.0508550 k
1.4034904 e
1.1783994 u
-0.3091201 s
NA u
0.9565287 g
-1.8219001 f
0.9026427 x
0.0810271 a
-1.6148682 b
-1.0559665 h
-0.2159946 z
-0.3384470 y
0.4555342 c
-0.1505646 f
0.0328752 w
NA w
-0.2078383 q
-0.0286051 r
-0.0947791 h
0.3294824 o
-0.3869947 a
2.1736815 c
-0.5690305 k
-0.8537561 u
-0.4280556 g
0.6632311 g
1.1194642 q
1.1107153 s
-1.5062202 m
0.1074509 k
-0.4102355 r
0.0467932 x
1.7779786 a
-0.1184538 i
-0.6490441 v
1.8082896 a
0.5468887 q
NA d
-0.2538139 g
1.2171161 v
-0.4482746 k
1.8866899 d
1.9568565 e
NA b
-0.4990151 u
-0.3337764 i
0.4392558 s
-1.2534422 j
0.1968101 u
0.8029541 h
0.5512663 f
1.1025894 t
1.6756721 k
NA x
-0.5589305 e
0.5934813 z
0.8241833 j
0.9650408 i
1.0277024 s
0.3230506 h
2.9541797 h
-1.2083768 b
0.8388813 n
2.3540340 t
-0.5321668 r
-0.8953112 n
0.0739845 n
0.7816222 o
1.3235045 g
-0.3069808 v
-0.6047814 s
2.7547985 q
-0.4825900 g
-0.5129993 r
-0.6819963 h
0.5282741 t
-0.5627690 l
-1.4856361 z
-0.2429064 g
-0.0922657 g
-2.0960369 y
0.0610342 r
-0.4337419 p
0.5375297 j
-0.5596916 e
-0.5250416 c
1.0765116 s
-1.1064533 k
NA m
-1.6600569 t
0.0873395 y
-0.9113817 d
-1.3242216 f
-0.4351004 r
-1.4628385 r
-1.2587931 l
-2.1086294 n
0.0887540 c
-0.5186215 g
-1.2653454 k
-0.5333801 l
-0.2490774 v
-0.6235974 z
-1.7701135 x
-0.4445836 n
1.3347229 l
-0.3823987 g
0.1003906 t
0.5771645 l
-0.2085325 k
-1.9295800 l
0.3912785 h
-0.7571245 r
0.8703931 c
1.5657836 w
2.4985689 z
0.3557403 p
NA l
0.9661479 l
0.3237207 g
0.8969652 d
-1.3118567 f
1.8417232 h
-1.0256235 d
1.8395749 z
-0.2767020 o
0.3377135 e
1.4134138 p
-1.6659996 j
-0.4221719 q
-0.5776856 s
-0.6872452 f
0.1863884 k
-2.0830088 h
-0.8896838 h
0.5750092 z
2.2454528 w
0.4508225 m
0.2164724 s
-0.8063512 m
0.2189437 i
-0.8243199 e
-1.3214242 r
0.4096809 m
-0.0910555 c
0.5401210 r
1.5387309 e
0.0361385 i
-0.7451741 s
0.2157046 m
0.1841107 s
-0.6768291 c
1.7561927 d
2.9360084 e
-0.6056314 o
-0.2628806 h
0.1173822 x
0.2972536 x
0.5642317 d
-0.5832306 j
1.0690668 n
1.0734903 n
0.5840616 t
-1.0124018 e
1.5458749 d
1.2388429 p
-0.6870397 q
0.5841100 o
1.1396555 u
-0.5375744 n
0.8085700 d
0.1438328 j
-0.2076511 g
-0.4600111 t
-0.4983542 k
-1.8233733 a
0.9869913 z
-1.6506067 y
2.1403023 f
0.1072091 x
0.6133065 t
-0.3925285 f
1.4186736 u
0.7105381 w
-0.2710239 v
-0.2377421 m
-1.7755345 n
0.8956385 a
0.3707762 x
0.5966338 d
-0.7908224 u
1.6983645 f
0.2552900 d
1.2261429 f
1.3265171 g
0.1991959 b
0.4187893 l
-0.1469677 e
1.3610246 w
0.9664725 m
-0.2768656 n
-0.6106332 k
-0.0684988 o
0.1057564 m
ss = summ %>% as.data.frame
library(pander)
pander(ss, round = 2)
x mean sd not_missing n z
a -0.02 1.24 39 40 Hey I am a very long string and I want to be wrapped
b -0.33 1.1 29 31 Hey I am a very long string and I want to be wrapped
c 0.29 1.08 35 36 Hey I am a very long string and I want to be wrapped
d 0.2 0.86 44 45 Hey I am a very long string and I want to be wrapped
e 0.23 1.04 45 46 Hey I am a very long string and I want to be wrapped
library(DT)
datatable(summ) %>% formatRound(columns = c("mean", "sd"))

Look at http://rmarkdown.rstudio.com/lesson-7.html and the Rmd: http://rmarkdown.rstudio.com/demos/6-tables.Rmd