I'm trying to build a styled table in descriptive analysis Rmarkdown for my binomial logit model .
descr
For now, I use the library command summarytools
and library printr
as follows (with my own data.frame):
```{r , eval=TRUE, echo=FALSE}
library(printr)
df<-mtcars
library(summarytools)
descr(datos_modelo, stats = c("mean", "sd", "max", "min"), na.rm =TRUE)
The problem is that the table that is generated for me puts the descriptive values in the columns and the variables by rows. But I have many variables. so it would be more correct if the descriptions were in the rows and the variables in the columns.
How can I "transpose" this table?
Knowing that I am developing a binomial logit with the package glm
with categorical variables (factor type so that R understands me) both for the endogenous variable and for most of the exogenous variables , is there any recommended package specifically for this type of descriptive analysis? I see that I have many packages available to me but I don't know which one is the most suitable for my work.
Imagining you have something like this:
You can use the traditional "transpose" of arrays,
t()
this because the output ofdescr()
is an object that inherits from the classmatrix
:And finally to keep the original order of the columns, you can do this:
With
order(match(rownames(new.df), colnames(mtcars)))
we redo the order of thedata.frame
original, the only drawback is that you end up with a flat array and not an object of typesummarytools
.