Reader small image

You're reading from  R Bioinformatics Cookbook - Second Edition

Product typeBook
Published inOct 2023
PublisherPackt
ISBN-139781837634279
Edition2nd Edition
Right arrow
Author (1)
Dan MacLean
Dan MacLean
author image
Dan MacLean

Professor Dan MacLean has a PhD in molecular biology from the University of Cambridge and gained postdoctoral experience in genomics and bioinformatics at Stanford University in California. Dan is now an honorary professor at the School of Computing Sciences at the University of East Anglia. He has worked in bioinformatics and plant pathogenomics, specializing in R and Bioconductor, and has developed analytical workflows in bioinformatics, genomics, genetics, image analysis, and proteomics at the Sainsbury Laboratory since 2006. Dan has developed and published software packages in R, Ruby, and Python, with over 100,000 downloads combined.
Read more about Dan MacLean

Right arrow

Working with lists in purrr

Lists are incredibly useful data structures that allow you to store and organize various types of objects, such as vectors, matrices, dataframes, and even other lists. Unlike vectors, matrices, or dataframes, lists can accommodate different data types and structures within a single object. This flexibility makes them a powerful tool for data manipulation and analysis in R.

As a result the purrr package provides lots of functions for working with lists, and in this short recipe, we’ll look at a few for summarizing, simplifying, and extracting data.

Getting ready

We’ll just need the purrr package.

How to do it…

We can manipulate lists in purrr using the following functions:

  1. Filter a list of elements:
    set.seed(2345)l <- list(  a = rnorm(10, mean = 1),  b = rnorm(10, mean = 10),  c = rnorm(10, mean = 20))library(purrr)keep(l, function(x) mean(x) >= 10)keep(l, ~ mean(.x) >= 10)detect_index...
lock icon
The rest of the page is locked
Previous PageNext Chapter
You have been reading a chapter from
R Bioinformatics Cookbook - Second Edition
Published in: Oct 2023Publisher: PacktISBN-13: 9781837634279

Author (1)

author image
Dan MacLean

Professor Dan MacLean has a PhD in molecular biology from the University of Cambridge and gained postdoctoral experience in genomics and bioinformatics at Stanford University in California. Dan is now an honorary professor at the School of Computing Sciences at the University of East Anglia. He has worked in bioinformatics and plant pathogenomics, specializing in R and Bioconductor, and has developed analytical workflows in bioinformatics, genomics, genetics, image analysis, and proteomics at the Sainsbury Laboratory since 2006. Dan has developed and published software packages in R, Ruby, and Python, with over 100,000 downloads combined.
Read more about Dan MacLean