O'Reilly logo

Data Manipulation with R by Jaynal Abedin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparing default R and plyr

In this section, we will compare code side by side to solve the same problem using both default R and plyr. Reusing the iris3 data, we are now interested in producing five number summary statistics for each variable group by species. The five numbers will be minimum, mean, median, maximum, and standard deviation. The output will be a list of data frames.

To calculate the summaries for the five numbers, follow these steps:

  1. Define a function that will calculate five number summary statistics for a given vector.
  2. Produce the output of this function in a data frame object.
  3. Apply this function in the iris3 dataset using a for loop.
  4. Apply the same function using the apply() function of the plyr package.

An example that explains ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required