Hello in this lecture we're going to learn how to compute the main statistical indicators by groups
or subsets with the package staffs the command aggregate the data frame.
I'm going to use is the mom and I will obtain the $236 indicators for the variable age by marital status
group so separated by marriage and on marriage subjects
that compute the mean first the average age it is ok.
I have to say that the aggregate function in the following way.
First of all I have to introduce the dependent variable in this case age from the date of frame the
mom and then I have to define the grouping variable.
You didn't have by option and here in the by option.
I have to use the function list least the argument of this functional least within my grouping variable
marital.
OK.
And then I have to specify what indicator I want to be computed using then there is the option fine
in that case the option barn will have the value mean because I want to compute the mean OK let's run
and see what happens.
I got this small table that shows me the age for the two groups.
So the married people are forty two point zero two years and they are married people are forty two point
zero or nine years.
The ages are pretty much the same for most people.
The average age is if I want to compute the standard deviation.
I only change the function here which is as the so that the little small downside of this of an aggregate
it computes the statistical indicators one by one not all at once.
So in order to compute the standard deviation I this.
Here are the standard deviations for the variable age on the two groups.
Married and unmarried.
Let's clear the console now and compute that median using the median Fantham here and the auction for
the media equals four to one for both groups married and married.
If I want to continue the veterans I will use the Ponson far.
Here are the variances in the table and so on and so on.
The Fontanne aggregate is very useful when we want to combine to factor categories.
That's a poll that I want to compute the statistical indicators for the same variable age.
But this time for all the combinations of the variable marital status and gender so married man married
women unmarried men unmarried women.
In this case here in the live function I have two arguments.
My two grouping variables marital and gender both from the more data set the function is men.
Let's see what happens.
Now let's clear the console's first and rom the line I did out here on the first line.
I have the means for the married female subject next to the mean for the unmarried female objects.
Next the men for the married male subject and next the ME and the average age four they are married
made subjects so that how you can combine the X Factor categories that call.
Thank you.