R Tutorial : Intermediate Functional Programming with purrr

DataCamp · Beginner ·🛠️ AI Tools & Apps ·6y ago

Key Takeaways

This video tutorial covers intermediate functional programming with purrr, a popular R package, focusing on the map function and its variants, including map_dbl and map2, to iterate over lists and perform computations.

Full Transcript

hello and welcome to this course on programming whisper I'm kunafa I'm a data scientist in our ARCA as you can only Amy there is a picture of me drinking coffee a big part of my day job is writing our code and I use / to help me optimize my workflow notably I use / for writing functions which is what you'll do in this course before starting this course make sure you've got some basic knowledge of iteration using / if you're not familiar with it there are some great resources that can help you learn about iteration with / if you're already familiar iterating with / you can start with schools right now almost every iteration process has two sides the first other elements we iterate over a second is we function we apply to each element / follows with format the first per function everyone learns is the map function map as two elements first dot X which is the object we are iterating over its object can either be a vector a list or a data frame a second part includes that F and V dot argument which represents the functional part of the iteration it's a description of what happens to each element of the object in this course you'll learn how to deal with the second half of a basic / skeleton the dot F and V dot arguments for this course I have extracted three lists from a dataset taken from the open data portal of a French city of Samara this dataset gathers account of a number of visits on the website some are up my fare each shop is newly created lists is a year 2014 2015 and 2016 it contains 12 sub lists corresponding to month each month is a vector with a number of website visits per day these list objects are an extraction of a full data set this list format is one you regularly encounter when carrying data on the web notably when you have to do with a JSON format which is passed as a nested list in our let's start with a refresher of per basic functions using these three lists first let's see the map function the map function runs without f function on each element of dot X and always return the list here we are mapping with some function on the list visit underscore 2015 when strength of Perl is with this types table this means that you always know up front the class of the output here for example we are using map and discord dbl map underscore GPL does the same operation as map but the output is different as you can see the result is a numeric vector rather than a list let's now imagine we want to add visits from 2015 and 2016 to do this I can use the map to function to get a list and its counterpart map to underscore TBL to get a vector of numeric what if we want to do the same computation as we won from the previous slide but with free lists in per there is no map free map for etc if you want to map over move on to elements you need to pass a list of elements to the P map function to iterate over elements in three or more lists you'll need to put all these lists in a novelist and pathways master list as the first argument of P map now it's your turn to refresh your memory

Original Description

Want to learn more? Take the full course at https://learn.datacamp.com/courses/intermediate-functional-programming-with-purrr at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work. --- Hello and welcome to this course on programming with purrr. I'm Colin Fay; I'm a data scientist and R hacker. As you can only hear me, here is a picture of me drinking coffee. A big part of my day job is writing R code, and I use purrr to help me optimize my workflow. Notably, I use purrr for writing functions, which is what you'll do in this course. Before starting this course, make sure you've got some basic knowledge of iteration using purrr. If you're not familiar with it, here are some great resources that can help you learn about iteration with purrr. If you're already familiar iterating with purrr, you can start this course right now! Almost every iteration process has two sides. The first are the elements we iterate over. The second is the function we apply to each element. purrr follows this format. The first purrr function everyone learns is the map() function. map() has two elements. First, .x, which is the object we are iterating over — this object can either be a vector, a list, or a data frame. The second part includes .f and the dot dot dot argument, which represents the functional part of the iteration. It's the description of what happens to each element of the object. In this course, you'll learn how to deal with the second half of the basic purrr skeleton: the .f and dot dot dot arguments. For this course, I have extracted three lists from a dataset taken from the open data portal of the French city of St. Malo. This dataset gathers a count of the number of visits on the website saint-malo.fr. Each of these newly created lists is a year: 2014, 2015, and 2016. Each contains 12 sublists corresponding to months. Each month is a vector with the number of website visits per day. These list objects are an
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from DataCamp · DataCamp · 0 of 60

← Previous Next →
1 SQL Server Tutorial: Date manipulation
SQL Server Tutorial: Date manipulation
DataCamp
2 R Tutorial: Intermediate Interactive Data Visualization with plotly in R
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
3 R Tutorial: Adding aesthetics to represent a variable
R Tutorial: Adding aesthetics to represent a variable
DataCamp
4 R Tutorial: Moving Beyond Simple Interactivity
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
5 Python Tutorial: Why use ML for marketing? Strategies and use cases
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
6 Python Tutorial: Preparation for modeling
Python Tutorial: Preparation for modeling
DataCamp
7 Python Tutorial: Machine Learning modeling steps
Python Tutorial: Machine Learning modeling steps
DataCamp
8 R Tutorial: The prior model
R Tutorial: The prior model
DataCamp
9 R Tutorial: Data & the likelihood
R Tutorial: Data & the likelihood
DataCamp
10 R Tutorial: The posterior model
R Tutorial: The posterior model
DataCamp
11 R Tutorial: An Introduction to plotly
R Tutorial: An Introduction to plotly
DataCamp
12 R Tutorial: Plotting a single variable
R Tutorial: Plotting a single variable
DataCamp
13 R Tutorial: Bivariate graphics
R Tutorial: Bivariate graphics
DataCamp
14 Python Tutorial: Customer Segmentation in Python
Python Tutorial: Customer Segmentation in Python
DataCamp
15 Python Tutorial: Time cohorts
Python Tutorial: Time cohorts
DataCamp
16 Python Tutorial: Calculate cohort metrics
Python Tutorial: Calculate cohort metrics
DataCamp
17 Python Tutorial: Cohort analysis visualization
Python Tutorial: Cohort analysis visualization
DataCamp
18 R Tutorial: Building Dashboards with flexdashboard
R Tutorial: Building Dashboards with flexdashboard
DataCamp
19 R Tutorial: Anatomy of a flexdashboard
R Tutorial: Anatomy of a flexdashboard
DataCamp
20 R Tutorial: Layout basics
R Tutorial: Layout basics
DataCamp
21 R Tutorial: Advanced layouts
R Tutorial: Advanced layouts
DataCamp
22 Python Tutorial: Time Series Analysis in Python
Python Tutorial: Time Series Analysis in Python
DataCamp
23 Python Tutorial: Correlation of Two Time Series
Python Tutorial: Correlation of Two Time Series
DataCamp
24 Python Tutorial: Simple Linear Regressions
Python Tutorial: Simple Linear Regressions
DataCamp
25 Python Tutorial: Autocorrelation
Python Tutorial: Autocorrelation
DataCamp
26 R Tutorial: The gapminder dataset
R Tutorial: The gapminder dataset
DataCamp
27 R Tutorial: The filter verb
R Tutorial: The filter verb
DataCamp
28 R Tutorial: The arrange verb
R Tutorial: The arrange verb
DataCamp
29 R Tutorial: The mutate verb
R Tutorial: The mutate verb
DataCamp
30 R Tutorial: What is cluster analysis?
R Tutorial: What is cluster analysis?
DataCamp
31 R Tutorial: Distance between two observations
R Tutorial: Distance between two observations
DataCamp
32 R Tutorial: The importance of scale
R Tutorial: The importance of scale
DataCamp
33 R Tutorial: Measuring distance for categorical data
R Tutorial: Measuring distance for categorical data
DataCamp
34 Python Tutorial: Plotting multiple graphs
Python Tutorial: Plotting multiple graphs
DataCamp
35 Python Tutorial: Customizing axes
Python Tutorial: Customizing axes
DataCamp
36 Python Tutorial: Legends, annotations, & styles
Python Tutorial: Legends, annotations, & styles
DataCamp
37 Python Tutorial: Introduction to iterators
Python Tutorial: Introduction to iterators
DataCamp
38 Python Tutorial: Playing with iterators
Python Tutorial: Playing with iterators
DataCamp
39 Python Tutorial: Using iterators to load large files into memory
Python Tutorial: Using iterators to load large files into memory
DataCamp
40 SQL Tutorial: Introduction to Relational Databases in SQL
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
41 SQL Tutorial: Tables: At the core of every database
SQL Tutorial: Tables: At the core of every database
DataCamp
42 SQL Tutorial: Update your database as the structure changes
SQL Tutorial: Update your database as the structure changes
DataCamp
43 Python Tutorial: Classification-Tree Learning
Python Tutorial: Classification-Tree Learning
DataCamp
44 Python Tutorial: Decision-Tree for Classification
Python Tutorial: Decision-Tree for Classification
DataCamp
45 Python Tutorial: Decision-Tree for Regression
Python Tutorial: Decision-Tree for Regression
DataCamp
46 Python Tutorial: Census Subject Tables
Python Tutorial: Census Subject Tables
DataCamp
47 Python Tutorial: Census Geography
Python Tutorial: Census Geography
DataCamp
48 Python Tutorial: Using the Census API
Python Tutorial: Using the Census API
DataCamp
49 R Tutorial: A/B Testing in R
R Tutorial: A/B Testing in R
DataCamp
50 R Tutorial: Baseline Conversion Rates
R Tutorial: Baseline Conversion Rates
DataCamp
51 R Tutorial: Designing an Experiment - Power Analysis
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
52 R Tutorial: Introduction to qualitative data
R Tutorial: Introduction to qualitative data
DataCamp
53 R Tutorial: Understanding your qualitative variables
R Tutorial: Understanding your qualitative variables
DataCamp
54 R Tutorial: Making Better Plots
R Tutorial: Making Better Plots
DataCamp
55 SQL Tutorial: OLTP and OLAP
SQL Tutorial: OLTP and OLAP
DataCamp
56 SQL Tutorial: Storing data
SQL Tutorial: Storing data
DataCamp
57 SQL Tutorial: Database design
SQL Tutorial: Database design
DataCamp
58 Python Tutorial: Introduction to spaCy
Python Tutorial: Introduction to spaCy
DataCamp
59 Python Tutorial: Statistical Models
Python Tutorial: Statistical Models
DataCamp
60 Python Tutorial: Rule-based Matching
Python Tutorial: Rule-based Matching
DataCamp

This tutorial teaches intermediate functional programming with purrr, covering the map function and its variants for iterating over lists and performing computations. By the end of this lesson, you'll be able to apply these concepts to your own data manipulation tasks.

Key Takeaways
  1. Refresh your knowledge of iteration using purrr
  2. Understand the map function and its variants (map_dbl, map2)
  3. Practice using map functions to iterate over lists
  4. Apply map functions to perform computations on lists
  5. Use pmap to iterate over multiple lists
💡 The map function in purrr allows you to iterate over lists and perform computations in a concise and efficient manner, making it a powerful tool for data manipulation.

Related AI Lessons

Up next
Salesforce Flow New Features (Summer '26) | Open Record, URL & Show Toast Messages
AITECHONE
Watch →