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...

The split(auto, auto$cylinders) function returns a list of data frames, where each data frame belongs to particulars levels of cylinders variable. To reference a data frame from the list, use the [ notation. Here, carslist[1] is a list of length 1 consisting of the first data frame that corresponds to three cylinder cars, and carslist[[1]] is the associated data frame for the three cylinder cars:

> str(carslist[1]) List of 1  $ 3:'data.frame': 4 obs. of  9 variables:    ..$ No          : int [1:4] 2 199 251 365    ..$ mpg         : num [1:4] 19 18 23.7 21.5    ..$ cylinders   : int [1:4] 3 3 3 3    ..$ displacement: num [1:4] 70 70 70 80    ..$ horsepower  : int [1:4] 97 90 100 110    ..$ weight      : int [1:4] 2330 2124 2420 2720  ..$ acceleration: num [1:4] ...

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