I am trying to prepare a frequency distribution table of a categorical variable in my data and I am using below code. But the output looks ok while I view it but not printing o
To print a data frame as a table in Markdown, one can use the kable()
function in knitr
.
library(knitr)
kable(aDataFrame)
For example...
data.frame()
with the kable()
function is really useful technique for communicating tabular information in R Markdown. For a couple of more complicated examples using this technique, please read my article Commentary on ToothGrowth Factorial ANOVA, where I compare Robert Kabacoff's analysis to the requirements of the Johns Hopkins University Statistical Inference course on Coursera.
regards,
Len
(11/22/2017) UPDATE: Responding to a comment from @sandhya-ghildiyal , here is how to exclude the blank row from the table output. If we save the result of table()
into an object, we can then use the extract operator [
within the kable()
function to exclude the row where the factor value is 1, the blank space.
theTable <- as.data.frame(table(STI$Q54))
kable(theTable[as.numeric(theTable$Var1) != 1,])