Skip to Content
R Programming Fundamentals
book

R Programming Fundamentals

by Kaelen Medeiros
September 2018
Beginner
206 pages
4h 27m
English
Packt Publishing
Content preview from R Programming Fundamentals

Splitting Datasets into Lists and Then Back Again

Herein, we will utilize the split() and unsplit() functions to separate and recreate datasets, and then use filter() from dplyr to supplement knowledge of how to split data.

In order to do so, the following steps have to be executed:

  1. Load the iris dataset if it is not currently loaded using the following code:
data(iris) 
  1. Split the iris dataset by species. This creates three lists of dataframes, each of which will only contain the information about one species of iris represented in the data. Verify that iris_species is a list by checking its type and check the class of iris_species[[1]]. This can be done with the help of the following code:
iris_species <- split(iris, iris$Species) 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Programming Fundamentals

R Programming Fundamentals

Samik Sen, Marcin Dubel
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781789612998Supplemental Content