I have been searching for quite a while now but couldn't really find a simple way. I have a df consisting of numerical values only and I want to Create a summary matrix out of my df.
DF
V1 V2 V3 V4 V5 ...
x1 y1 z1 1 c1
x2 NA z2 0 c2
x3 y3 z3 1 NA
...
V4 is originally a TRUE/FALSE variable tranformed into numerical variable which should usually work. I want to obtain the following:
N Mean SD Min 1st Median 3rd Max
V1
V2
V3
V4
V5
...
with the according values for N, Mean, SD, Min, 1st, Median, 3rd, Max.
I have tried the simple
as.data.frame(summary(DF))
I have tried stargazer which doesn't work for some reason ( I am guessing because I have binal variables)
stargazer(DF, type= "html", nobs = TRUE, type="html", mean.sd = TRUE, median = TRUE, iqr = TRUE,
+ digits=2, align=T)
and I read something about qwraps2_summary_table. But they all seem to give a different "design" of table than what I am looking for.
I know I can also run a loop like:
for(i in (1:length(DF)){
sum$N<-(????)
sum$Mean<-mean(DF[i])
....}
But this is not the nicest solution. Any tipps? Thank you!
Here a part of my dataset
structure(list(Year = c(2011, 2012, 2013, 2014, 2015, 2016, 2017,
2018, 2018, 2011), Occurences = c(9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 2L, 9L), Balance = c(-1.14, 1.05, -1.06, 1.01, 1.01, 1.01,
-1.09, -1, -1.04, -1.03), Withdrawal = c(43200, 41080, 43400,
43183, 42600, 42100, 45900, 46000, 3892008, 48374), Verification_SA = c(NA,
NA, NA, NA, 1, 1, NA, 1, 1, NA), Classification_num = c(NA, NA,
NA, NA, 3, 2, NA, 4, 4, NA), Interaction_Verification_Classification = c(NA,
NA, NA, NA, 3, 2, NA, 4, 4, NA), KnowledgeSources = c(1, 1, 1,
0, 1, 1, 1, 1, 1, 0), KnowledgeDischarge = c(0, 0, 0, 0, 0, 1,
1, 1, 1, 0), Scarcity_watershed = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), Scarcity_country = c(NA, NA, NA, NA, NA, NA, NA, NA, 3.35,
NA), Knowledge_Watershed = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Knowledge_Facilities = c(0,
0, 0, 0, 0, 0, 0, 0, 1, 1), Importance_num = c(NA, NA, NA, 3,
3, 3, 3, 3, 5, NA), DetrimentalImpacts_num = c(0, 0, 1, 0, 0,
0, 0, 0, 0, 0), Responsibility_num = c(1, 1, 1, 2, 2, 2, 2, 3,
3, 1)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
))