O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

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

How it works...

In step 1, ddply is used. This function takes a data frame as input and produces a data frame as output. The first argument is the auto data frame. The second argument, cylinders, describes the way to split the data. The third argument is the function to perform on the resulting components. We can add additional arguments if the function needs arguments. We can specify the splitting factor using the formula interface ~ cylinders, as the second option of step 1 shows.

Step 2 shows how data splitting can occur across multiple variables as well. We use the c("cylinders","model_year") vector format to split the data using two variables. We also name the variables as mean, min, and max, instead of the default V1, V2, and so on. ...

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