liveBook · Manning

Purrr

As explained in Statistics Slam Dunk

purrr is an R package that provides tools for applying functions iteratively and working with lists and functional programming patterns.

purrr is a tidyverse package for applying functions iteratively to lists and columns. In data wrangling, map_df() applies class() across variables and returns the results as a data frame. section 9.3

Inspecting NBA data types

After reducing an NBA dataset to six variables, map_df(mydata, class) reveals that location and result fields are character vectors while days-off fields are integers. The variables are then converted to factors for analysis. section 9.3

map_df(mydata, class)
## # A tibble: 1 × 6
##   teamLoc   teamRslt  teamDayOff opptLoc   opptRslt  opptDayOff
##   <chr>     <chr>     <chr>      <chr>     <chr>     <chr>     
## 1 character character integer    character character integer

mydata$teamLoc <- as.factor(mydata$teamLoc)
mydata$teamRslt <- as.factor(mydata$teamRslt)
mydata$teamDayOff <- as.factor(mydata$teamDayOff)
mydata$opptLoc <- as.factor(mydata$opptLoc)
mydata$opptRslt <- as.factor(mydata$opptRslt)
mydata$opptDayOff <- as.factor(mydata$opptDayOff)

Inspect the exact map_df() output and the subsequent factor conversions. section 9.3

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates one practical map_df() workflow and stops short of explaining purrr internals or broader function families.
Examples
Uses map_df(class) on six NBA location, result, and days-off variables.
What it assumes
Assumes basic R data frames and functions while demonstrating class inspection and factor conversion.
What you can do after
Apply map_df() to inspect multiple variable classes and prepare columns for analysis.
How it connects
Connects purrr with tidyverse, data wrangling, dplyr, and factor conversion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.