I really like the modelsummary
package and i'm trying to produce a single table that mixes descriptive statistics of different types. The first part is easy: I can make basic descriptives of var2
and var3
before. I can't get the second part right, though.
- I'd like to get a count of the unique entries of the variable
var1
, i.e. 26. - I'd like to be able to combine the two into one table.
var1<-rep(LETTERS, 5)
var2<-rnorm(length(var1), mean=50, sd=10)
var3<-rnorm(length(var1), mean=10, sd=5)
df<-data.frame(var1, var2, var3)
library(gr)
library(modelsummary)
#This gets the descriptives of var2 and var3
datasummary(var2+var3~Mean+SD+N, data=df)
#htis returns a long column of the number of entries of each value of var1; I would just like the number 26 here and combine it with the above
datasummary(var1~length, data=df)
Based on
add_row
(https://vincentarelbundock.github.io/modelsummary/articles/datasummary.html#add_rows)