Frequency distribution of a categorical variable in R

前端 未结 1 1966
予麋鹿
予麋鹿 2021-01-21 19:53

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

相关标签:
1条回答
  • 2021-01-21 20:19

    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,])
    
    0 讨论(0)
提交回复
热议问题