Aggregating basic statistics group-wise in R

Many times, while doing Statistical analysis, we have to evaluate the descriptive statistics like mean, standard deviation and so on for a number of variables, group-wise. Most of the Statistical packages like SAS, SPSS and so on provide these features. In R, the data.table package is very useful for aggregating these types of results and to tabulate them. It offers fast aggregation of large data , fast ordered joins, fast add/modify/delete of columns by group using no copies at all, list columns and a fast file reader (fread). In addition, the tables package and psych package’s describeBy method were also found to be useful for generating this type of results. As an exercise, the iris data is considered, which contains the data of four variables Sepal Length(SL), Sepal Width(SW), Petal Length(PL) and Petal Width(PW) of three species setosa, versicolor and virginica. Three types of results were generated, utilizing all the three packages listed above.

1.Mean and Standard deviation for all the four variables specie-wise using data-table package

data-table-results
2.Mean and Standard deviation for all the four variables specie-wise using tables package

table-output
3.Mean and Standard deviation for all the four variables specie-wise using psych package

psych-output

Leave a Reply