'how do I add 'min' and 'max' column in a table of descriptive statistics in Rmarkdown?
I've just started using R in my first year of uni and I'm having a lot of issues. For this task I'm trying to usw Rmarkdown. I'm trying to produce a table of descriptive statistics which include observations, mean, SD, Min, and Max but I can't seem to add the last two.
Sierra_Leone_Trunc <- select(Sierra_Leone, civilian_deaths, ethnic_pol, id_lntroop, ln_pop, ln_ppp, capdist, nlights_calib_mean, diamprim_y, prior_violence, excluded)
kable(describe(Sierra_Leone_Trunc))
kable(describe(Sierra_Leone_Trunc, skew = F, ranges = F), digits = 3, caption = "Table 1. Descriptive Statistics")
I got my variables and when I use kable(describe()) I get a table of ALL the stats, but when I remove skew and ranges it removes everything except 'vars', 'n', 'mean', 'sd', 'se'.
How do I get the right statistics I want? Thanks in advance.
Solution 1:[1]
I think the issue has to do with describe (I assume from psych package) and not with kable or rmd.
In describe, when you include ranges = F it does not include range statistics, which include min, max, and range.
Here is one approach that might allow for flexibility and clarity. You didn't include what packages you're using, but this will work with psych and dplyr (noticing you used select). I will use mtcars data.frame as an example.
First, select which variables from you data.frame you want your summary statistics on. Then, use describe (and if skewness/kurtosis are not needed, can use skew = F). Then, select the summary statistics you want, such as n, mean, sd, min, and max. Then pass to kable.
library(dplyr)
library(psych)
library(kableExtra)
mtcars %>%
select(mpg, cyl, disp) %>%
describe(skew = F) %>%
select(n, mean, sd, min, max) %>%
kable()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ben |
