# Flowchart

# Data set defined in dep_regression.Rmd
summary_list<-function(var){
  v<-factor(var)
  x<-levels(v)
  y<-summary(v)
  lst<-list(data.frame(matrix(y,nrow=length(x),byrow = TRUE,dimnames = list(x,deparse(substitute(var))))))  # deparse and substitue is used to get the name of the vector for naming the matrix. Nice!
  return(lst)
}

slist<-summary_list(dta$drop)

dta<-dta[dta$drop=="yes",]

vars_l<-c("open_treat","wants_out","side_effect","side_effect2")
for (i in 1:length(vars_l)){
  z<-summary_list(dta[,vars_l[i]])
  colnames(z[[1]])<-vars_l[i]
  slist[length(slist)+1] <- z
}
