Aggregating basic statistics group-wise in R

[This article was first published on Krishna's R Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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

To leave a comment for the author, please follow the link and comment on their blog: Krishna's R Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)