How to make a grid with psych::describeBy?

Hi! i want to create something like a grid for the output i get from the fuction

> library(psych)
> psych::describeBy(menores$EDAD, menores$JPG_VG_VINCULO)`

This basically gives me the mean, median, sd, range ages from the sample i have in my dataframe.

>  Descriptive statistics by group 
> group: 1
>    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
> X1    1 40 7.88 1.76      8    7.94 1.48   4  11     7 -0.23    -0.86 0.28
> ------------------------------------------------------------------------------------------ 
> group: 2
>    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
> X1    1 19 9.37 2.95      9    9.29 2.97   5  15    10  0.5    -0.63 0.68
> ------------------------------------------------------------------------------------------ 
> group: 3
>    vars  n mean   sd median trimmed mad min max range skew kurtosis  se
> X1    1 15 11.6 1.92     11   11.31   0  10  17     7 1.72     1.93 0.5
> ------------------------------------------------------------------------------------------ 
> group: 4
>    vars n mean sd median trimmed mad min max range skew kurtosis se
> X1    1 1   17 NA     17      17   0  17  17     0   NA       NA NA

I've tryied with fuctions like grid.table but can't make it work with this.

The describeBy function is outputting a list of data.frames. That means that each group in you output is a separate data frame. Try this:

mydata[1]
# or
mydata[[1]]

Without any sample data, it's hard to be sure but I think you might get
something useful just by collapsing that list into a data.frame. If we call your output "mydata", try something like this

mydata  <-  describeBy(menores$EDAD, menores$JPG_VG_VINCULO)
df  <-  rbind(mydata)
df

the function grid.table is will hive you an image not a usable data.frame

Actually what i need is an image displaying that information. Sorry i didn't clarify

Oh then I think my approach + table.grid may do it but there are a lot of tables packages that may give a better layout and can be converted to an image.

Good luck.

1 Like

I found a way to make this.

> library(psych)
> library(DT)
> 
> adultosxcond <- psych::describeBy(mayores$EDAD, mayores$JPC_VI_COND, skew=FALSE)
> adultosxcond2 <-do.call("rbind",adultosxcond)
> datatable(adultosxcond2)

The output looks something like this:

Congrats' looks good

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.