SlideShare a Scribd company logo
How to deal with
nested lists in R?  
Using the purrr, furrr and future
packages in practice.
Lidia Kołakowska • Data Scientist, Sotrender
Why R? 2019 Conference • Warsaw, 29.09.2019
}
Data set
◉ Downloaded data on social issues, elections or
politics ads from Facebook Ad Library API
◉ JSON-formatted response
◉ Facebook allows publish articles or research
about or related to the use of the Ad Library
API e.g. political advertising analysis
2
3
Example nested list loaded from JSON
Nested lists
◉ Elements of list e.g. demographic_distribution
are data frames – we cannot easily flatten
them into a data frame
◉ Custom ids are needed for elements in nested
list elements to connect them to the parent
elements
4
How to deal with data
in nested list?
5
Key packages
6
purrr furrr
future
/HenrikBengtsson/future
/tidyverse/purrr /DavisVaughan/furrr
Environment setup
7
# load necessary packages
library(dplyr)
library(jsonlite)
library(purrr)
library(fs)
library(furrr)
library(future)
# define project path and data directory
proj.dir = "/home/lkolakowska/path/to/your/project/”
data.dir = proj.dir %>%
paste0("data/")
Enviroment
8
Loading data into R
9
# 1. load data from json format
data.microtargeting = data.dir %>%
dir_ls %>%
map(~dir_ls(.x, regexp = "json")) %>%
unlist() %>%
map(fromJSON) %>%
map("data")
What is anonymous functions?
◉ They are used in apply() functions family
◉ In purrr packages they are user-specified,
one-sided formula
◉ They have no identity and no name
◉ They will not live in the global environment
10
Examples
11
# anonymous function syntax in purrr
your.list = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] , 233,
377, 610, 987, 1597
purrr::map(your.list, ~.x * 0.75)
purrr::map(your.list, function(single.element){
single.element * 0.75
})
“
„When it’s not worth the
effort to give it a name"
12
When should you use
anonymous functions?
Hadley Wickham
Anonymous functions in pipe
13
# 2. add custom ids to nested data frames
data.microtargeting = data.microtargeting %>%
purrr::compact() %>%
map(function(df) {
custom_ad_id = seq( 1, nrow(df), by = 1)
df = df %>%
mutate(ad_id = paste0(page_id, "_", custom_ad_id))
return(df)
})
The process takes too long…
14
Let’s parallaize software!
◉ Speed up processing
◉ Decrease memory footprint
◉ Avoid data transfer
15
16
mclapply
Parallization using
pipe in R
17
# 3. parallaize process
plan(multicore= 6)
data.microtargeting = data.microtargeting %>%
purrr::compact() %>%
future_map(function(df) {
custom_ad_id = seq( 1, nrow(df), by = 1)
df = df %>%
mutate(ad_id = paste0(page_id, "_", custom_ad_id))
return(df)
}, .progress = TRUE)
Summary
◉ Working with nested lists can be very efficient
◉ First perform operations on the individual
elements of the list, only then combine them
into one large data frame
◉ Speed up your work by performing a
parallaized process
18
Resources that made it easier
to create this presentation ☺
◉ H. Bengtsson, „Future: Parallel & Distributed Processing in R for Everyone”, eRum 2018, Budapest
◉ H. Bengtsson, „Future: Friendly Parallel Processing in R for Everyone”, SatRday Paris 2019
◉ M. Jones, „Quick Intro to Parallel Computing in R”, 2017
◉ L. Singham, „Anonymous Functions in R and Python”, 2017
◉ H.Wickham, „Advanced R” - Functional programming
◉ Cool but useless, „Anonymous Functions in R - Part 1”, 2019
19
20
I am Lidia Kołakowska
You can find me at
◉ /in/lidia-kolakowska/
◉ /lidkol
Thanks!

More Related Content

What's hot (19)

Geospatial data
Geospatial dataGeospatial data
Geospatial data
MostafaAliAbbas
 
Text Mining with Node.js - Philipp Burckhardt, Carnegie Mellon University
Text Mining with Node.js - Philipp Burckhardt, Carnegie Mellon UniversityText Mining with Node.js - Philipp Burckhardt, Carnegie Mellon University
Text Mining with Node.js - Philipp Burckhardt, Carnegie Mellon University
NodejsFoundation
 
Big Data & Hadoop Data Analysis
Big Data & Hadoop Data AnalysisBig Data & Hadoop Data Analysis
Big Data & Hadoop Data Analysis
Koushik Mondal
 
Topic modeling using big data analytics
Topic modeling using big data analytics Topic modeling using big data analytics
Topic modeling using big data analytics
Farheen Nilofer
 
google chart
google chartgoogle chart
google chart
kimsrung lov
 
Big Data and Hadoop Training in Bangalore by myTectra
Big Data and Hadoop Training in Bangalore by myTectraBig Data and Hadoop Training in Bangalore by myTectra
Big Data and Hadoop Training in Bangalore by myTectra
myTectra Learning Solutions Private Ltd
 
Be lazy & scale
Be lazy & scaleBe lazy & scale
Be lazy & scale
logmatic.io
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Hive integration: HBase and Rcfile__HadoopSummit2010
Hive integration: HBase and Rcfile__HadoopSummit2010Hive integration: HBase and Rcfile__HadoopSummit2010
Hive integration: HBase and Rcfile__HadoopSummit2010
Yahoo Developer Network
 
HDF-EOS Datablade: Efficiently Serving Earth Science Data
HDF-EOS Datablade: Efficiently Serving Earth Science DataHDF-EOS Datablade: Efficiently Serving Earth Science Data
HDF-EOS Datablade: Efficiently Serving Earth Science Data
The HDF-EOS Tools and Information Center
 
The National Digital Stewardship Residency at PBS
The National Digital Stewardship Residency at PBSThe National Digital Stewardship Residency at PBS
The National Digital Stewardship Residency at PBS
squaredsong
 
Try It The Google Way .
Try It The Google Way .Try It The Google Way .
Try It The Google Way .
abhinavbom
 
The Vision for Graph Database from Postgres
The Vision for Graph Database from PostgresThe Vision for Graph Database from Postgres
The Vision for Graph Database from Postgres
EDB
 
Managing research data at Bristol
Managing research data at BristolManaging research data at Bristol
Managing research data at Bristol
Simon Price
 
Sql can be cool again
Sql can be cool againSql can be cool again
Sql can be cool again
Junjun Olympia
 
Ross McDonald - PgRouting in QGIS
Ross McDonald - PgRouting in QGISRoss McDonald - PgRouting in QGIS
Ross McDonald - PgRouting in QGIS
Ross McDonald
 
D3 data, user, interaction
D3  data, user, interactionD3  data, user, interaction
D3 data, user, interaction
Dummas
 
Overview of Dan Olteanu's Research presentation
Overview of Dan Olteanu's Research presentationOverview of Dan Olteanu's Research presentation
Overview of Dan Olteanu's Research presentation
DBOnto
 
Dc python meetup
Dc python meetupDc python meetup
Dc python meetup
Jeffrey Clark
 
Text Mining with Node.js - Philipp Burckhardt, Carnegie Mellon University
Text Mining with Node.js - Philipp Burckhardt, Carnegie Mellon UniversityText Mining with Node.js - Philipp Burckhardt, Carnegie Mellon University
Text Mining with Node.js - Philipp Burckhardt, Carnegie Mellon University
NodejsFoundation
 
Big Data & Hadoop Data Analysis
Big Data & Hadoop Data AnalysisBig Data & Hadoop Data Analysis
Big Data & Hadoop Data Analysis
Koushik Mondal
 
Topic modeling using big data analytics
Topic modeling using big data analytics Topic modeling using big data analytics
Topic modeling using big data analytics
Farheen Nilofer
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Hive integration: HBase and Rcfile__HadoopSummit2010
Hive integration: HBase and Rcfile__HadoopSummit2010Hive integration: HBase and Rcfile__HadoopSummit2010
Hive integration: HBase and Rcfile__HadoopSummit2010
Yahoo Developer Network
 
The National Digital Stewardship Residency at PBS
The National Digital Stewardship Residency at PBSThe National Digital Stewardship Residency at PBS
The National Digital Stewardship Residency at PBS
squaredsong
 
Try It The Google Way .
Try It The Google Way .Try It The Google Way .
Try It The Google Way .
abhinavbom
 
The Vision for Graph Database from Postgres
The Vision for Graph Database from PostgresThe Vision for Graph Database from Postgres
The Vision for Graph Database from Postgres
EDB
 
Managing research data at Bristol
Managing research data at BristolManaging research data at Bristol
Managing research data at Bristol
Simon Price
 
Ross McDonald - PgRouting in QGIS
Ross McDonald - PgRouting in QGISRoss McDonald - PgRouting in QGIS
Ross McDonald - PgRouting in QGIS
Ross McDonald
 
D3 data, user, interaction
D3  data, user, interactionD3  data, user, interaction
D3 data, user, interaction
Dummas
 
Overview of Dan Olteanu's Research presentation
Overview of Dan Olteanu's Research presentationOverview of Dan Olteanu's Research presentation
Overview of Dan Olteanu's Research presentation
DBOnto
 

Similar to How to deal with nested lists in R? (20)

Tackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in RTackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in R
Lun-Hsien Chang
 
How to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in RHow to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in R
Paul Bradshaw
 
JSON and MongoDB in R
JSON and MongoDB in RJSON and MongoDB in R
JSON and MongoDB in R
Leon Kim
 
R training2
R training2R training2
R training2
Hellen Gakuruh
 
A Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for EveryoneA Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for Everyone
inside-BigData.com
 
Data analystics with R module 3 cseds vtu
Data analystics with R module 3 cseds vtuData analystics with R module 3 cseds vtu
Data analystics with R module 3 cseds vtu
LalithauLali
 
data frames.pptx
data frames.pptxdata frames.pptx
data frames.pptx
RacksaviR
 
20130215 Reading data into R
20130215 Reading data into R20130215 Reading data into R
20130215 Reading data into R
Kazuki Yoshida
 
欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】
juliancopeman444
 
美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】
美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】
美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】
muslimbabu372
 
欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】
欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】
欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】
landrielgabriel274
 
欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】
欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】
欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】
mayngozi145
 
欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】
mukeshomran942
 
欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】
欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】
欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】
concepsionchomo153
 
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
siomaranico724
 
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
terkesimamishy540
 
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
juliancopeman444
 
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
stellacovaleda199
 
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
valvereliz227
 
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
valvereliz227
 
Tackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in RTackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in R
Lun-Hsien Chang
 
How to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in RHow to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in R
Paul Bradshaw
 
JSON and MongoDB in R
JSON and MongoDB in RJSON and MongoDB in R
JSON and MongoDB in R
Leon Kim
 
A Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for EveryoneA Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for Everyone
inside-BigData.com
 
Data analystics with R module 3 cseds vtu
Data analystics with R module 3 cseds vtuData analystics with R module 3 cseds vtu
Data analystics with R module 3 cseds vtu
LalithauLali
 
data frames.pptx
data frames.pptxdata frames.pptx
data frames.pptx
RacksaviR
 
20130215 Reading data into R
20130215 Reading data into R20130215 Reading data into R
20130215 Reading data into R
Kazuki Yoshida
 
欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯竞猜-欧洲杯竞猜押注-欧洲杯竞猜押注官网|【​网址​🎉ac99.net🎉​】
juliancopeman444
 
美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】
美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】
美洲杯投注-美洲杯投注竞猜app-竞猜美洲杯投注app|【​网址​🎉ac10.net🎉​】
muslimbabu372
 
欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】
欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】
欧洲杯外围-欧洲杯外围下注网址-欧洲杯外围下注网站|【​网址​🎉ac44.net🎉​】
landrielgabriel274
 
欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】
欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】
欧洲杯体彩-欧洲杯体彩比分-欧洲杯体彩比分投注|【​网址​🎉ac44.net🎉​】
mayngozi145
 
欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】
欧洲杯足彩-欧洲杯足彩押注-欧洲杯足彩押注官网|【​网址​🎉ac99.net🎉​】
mukeshomran942
 
欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】
欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】
欧洲杯投注-欧洲杯投注外围盘口-欧洲杯投注盘口app|【​网址​🎉ac22.net🎉​】
concepsionchomo153
 
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
siomaranico724
 
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
terkesimamishy540
 
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
juliancopeman444
 
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
stellacovaleda199
 
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
valvereliz227
 
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
valvereliz227
 

More from Sotrender (19)

Training and deploying ML models with Google Cloud Platform
Training and deploying ML models with Google Cloud PlatformTraining and deploying ML models with Google Cloud Platform
Training and deploying ML models with Google Cloud Platform
Sotrender
 
Transfer learning in NLP
Transfer learning in NLPTransfer learning in NLP
Transfer learning in NLP
Sotrender
 
Handling problem of hand-labeled training data with data programming and weak...
Handling problem of hand-labeled training data with data programming and weak...Handling problem of hand-labeled training data with data programming and weak...
Handling problem of hand-labeled training data with data programming and weak...
Sotrender
 
State of the art as to content creation using AI
State of the art as to content creation using AIState of the art as to content creation using AI
State of the art as to content creation using AI
Sotrender
 
Paid communication analysis on Facebook. Reach and cost estimations report.
Paid communication analysis on Facebook. Reach and cost estimations report.Paid communication analysis on Facebook. Reach and cost estimations report.
Paid communication analysis on Facebook. Reach and cost estimations report.
Sotrender
 
People interest analysis on Facebook.
People interest analysis on Facebook.People interest analysis on Facebook.
People interest analysis on Facebook.
Sotrender
 
Brands image across the internet including social media
Brands image across the internet including social mediaBrands image across the internet including social media
Brands image across the internet including social media
Sotrender
 
Audience Scan report based on social media data
Audience Scan report based on social media dataAudience Scan report based on social media data
Audience Scan report based on social media data
Sotrender
 
Fanpage Trends UK October 2016
Fanpage Trends UK October 2016Fanpage Trends UK October 2016
Fanpage Trends UK October 2016
Sotrender
 
Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?
Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?
Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?
Sotrender
 
Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...
Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...
Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...
Sotrender
 
10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy
10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy 10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy
10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy
Sotrender
 
Naked truth about porn on social media
Naked truth about porn on social mediaNaked truth about porn on social media
Naked truth about porn on social media
Sotrender
 
Posting frequency on Facebook
Posting frequency on FacebookPosting frequency on Facebook
Posting frequency on Facebook
Sotrender
 
Conservatives in the social media
Conservatives in the social mediaConservatives in the social media
Conservatives in the social media
Sotrender
 
Who would win the Oscars in Social Media?
Who would win the Oscars in Social Media?Who would win the Oscars in Social Media?
Who would win the Oscars in Social Media?
Sotrender
 
How brands can benefit from Super Bowl by using social media
How brands can benefit from Super Bowl by using social mediaHow brands can benefit from Super Bowl by using social media
How brands can benefit from Super Bowl by using social media
Sotrender
 
Social media analytics - Sotrender training in Jakarta, Indonesia
Social media analytics - Sotrender training in Jakarta, Indonesia Social media analytics - Sotrender training in Jakarta, Indonesia
Social media analytics - Sotrender training in Jakarta, Indonesia
Sotrender
 
What should we say to engage thousands?
What should we say to engage thousands?What should we say to engage thousands?
What should we say to engage thousands?
Sotrender
 
Training and deploying ML models with Google Cloud Platform
Training and deploying ML models with Google Cloud PlatformTraining and deploying ML models with Google Cloud Platform
Training and deploying ML models with Google Cloud Platform
Sotrender
 
Transfer learning in NLP
Transfer learning in NLPTransfer learning in NLP
Transfer learning in NLP
Sotrender
 
Handling problem of hand-labeled training data with data programming and weak...
Handling problem of hand-labeled training data with data programming and weak...Handling problem of hand-labeled training data with data programming and weak...
Handling problem of hand-labeled training data with data programming and weak...
Sotrender
 
State of the art as to content creation using AI
State of the art as to content creation using AIState of the art as to content creation using AI
State of the art as to content creation using AI
Sotrender
 
Paid communication analysis on Facebook. Reach and cost estimations report.
Paid communication analysis on Facebook. Reach and cost estimations report.Paid communication analysis on Facebook. Reach and cost estimations report.
Paid communication analysis on Facebook. Reach and cost estimations report.
Sotrender
 
People interest analysis on Facebook.
People interest analysis on Facebook.People interest analysis on Facebook.
People interest analysis on Facebook.
Sotrender
 
Brands image across the internet including social media
Brands image across the internet including social mediaBrands image across the internet including social media
Brands image across the internet including social media
Sotrender
 
Audience Scan report based on social media data
Audience Scan report based on social media dataAudience Scan report based on social media data
Audience Scan report based on social media data
Sotrender
 
Fanpage Trends UK October 2016
Fanpage Trends UK October 2016Fanpage Trends UK October 2016
Fanpage Trends UK October 2016
Sotrender
 
Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?
Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?
Insighty z social media - jak je wyciągnąć i dlaczego nie zawsze ma to sens?
Sotrender
 
Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...
Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...
Tego się nie da odzobaczyć - czego dowiedzieliśmy się o gustach Polaków przez...
Sotrender
 
10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy
10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy 10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy
10 narzędzi dla marketerów, które wykorzystasz w codziennej pracy
Sotrender
 
Naked truth about porn on social media
Naked truth about porn on social mediaNaked truth about porn on social media
Naked truth about porn on social media
Sotrender
 
Posting frequency on Facebook
Posting frequency on FacebookPosting frequency on Facebook
Posting frequency on Facebook
Sotrender
 
Conservatives in the social media
Conservatives in the social mediaConservatives in the social media
Conservatives in the social media
Sotrender
 
Who would win the Oscars in Social Media?
Who would win the Oscars in Social Media?Who would win the Oscars in Social Media?
Who would win the Oscars in Social Media?
Sotrender
 
How brands can benefit from Super Bowl by using social media
How brands can benefit from Super Bowl by using social mediaHow brands can benefit from Super Bowl by using social media
How brands can benefit from Super Bowl by using social media
Sotrender
 
Social media analytics - Sotrender training in Jakarta, Indonesia
Social media analytics - Sotrender training in Jakarta, Indonesia Social media analytics - Sotrender training in Jakarta, Indonesia
Social media analytics - Sotrender training in Jakarta, Indonesia
Sotrender
 
What should we say to engage thousands?
What should we say to engage thousands?What should we say to engage thousands?
What should we say to engage thousands?
Sotrender
 

Recently uploaded (20)

"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
Fwdays
 
lecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptxlecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptx
obsinaafilmakuush
 
time_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptxtime_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptx
stefanopinto1113
 
HPC High Performance Course Presentation.pptx
HPC High Performance Course Presentation.pptxHPC High Performance Course Presentation.pptx
HPC High Performance Course Presentation.pptx
naziaahmadnm
 
Data Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBiData Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBi
Krishnapriya975316
 
Али махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptxАли махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptx
palr19411
 
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
aishwaryavdcw
 
How to Choose the Right Online Proofing Software
How to Choose the Right Online Proofing SoftwareHow to Choose the Right Online Proofing Software
How to Choose the Right Online Proofing Software
skalatskayaek
 
Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...
Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...
Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...
smrithimuralidas
 
531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...
531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...
531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...
spratistha569
 
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost  Data Protection People.pdfGDPR Audit - GDPR gap analysis cost  Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
Data Protection People
 
BADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and InterpretationBADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and Interpretation
srishtisingh1813
 
Chronic constipation presentaion final.ppt
Chronic constipation presentaion final.pptChronic constipation presentaion final.ppt
Chronic constipation presentaion final.ppt
DrShashank7
 
Tableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdfTableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdf
elinavihriala
 
Chapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I willChapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I will
SotheaPheng
 
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxHow Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
sofiawilliams5966
 
egc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPTegc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPT
huyenmy200809
 
refractiveindexexperimentdetailed-250528162156-4516aa1c.pptx
refractiveindexexperimentdetailed-250528162156-4516aa1c.pptxrefractiveindexexperimentdetailed-250528162156-4516aa1c.pptx
refractiveindexexperimentdetailed-250528162156-4516aa1c.pptx
KannanDamodaram
 
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docxGeospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
sofiawilliams5966
 
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptxArtificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
AbhijitPal87
 
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
Fwdays
 
lecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptxlecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptx
obsinaafilmakuush
 
time_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptxtime_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptx
stefanopinto1113
 
HPC High Performance Course Presentation.pptx
HPC High Performance Course Presentation.pptxHPC High Performance Course Presentation.pptx
HPC High Performance Course Presentation.pptx
naziaahmadnm
 
Data Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBiData Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBi
Krishnapriya975316
 
Али махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptxАли махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptx
palr19411
 
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
aishwaryavdcw
 
How to Choose the Right Online Proofing Software
How to Choose the Right Online Proofing SoftwareHow to Choose the Right Online Proofing Software
How to Choose the Right Online Proofing Software
skalatskayaek
 
Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...
Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...
Mastering Data Science: Unlocking Insights and Opportunities at Yale IT Skill...
smrithimuralidas
 
531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...
531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...
531a07261283c4efb4cbae5fb8. Tele2 Sverige AB v post-och telestyrelsen, C-203:...
spratistha569
 
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost  Data Protection People.pdfGDPR Audit - GDPR gap analysis cost  Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
Data Protection People
 
BADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and InterpretationBADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and Interpretation
srishtisingh1813
 
Chronic constipation presentaion final.ppt
Chronic constipation presentaion final.pptChronic constipation presentaion final.ppt
Chronic constipation presentaion final.ppt
DrShashank7
 
Tableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdfTableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdf
elinavihriala
 
Chapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I willChapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I will
SotheaPheng
 
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxHow Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
sofiawilliams5966
 
egc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPTegc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPT
huyenmy200809
 
refractiveindexexperimentdetailed-250528162156-4516aa1c.pptx
refractiveindexexperimentdetailed-250528162156-4516aa1c.pptxrefractiveindexexperimentdetailed-250528162156-4516aa1c.pptx
refractiveindexexperimentdetailed-250528162156-4516aa1c.pptx
KannanDamodaram
 
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docxGeospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
sofiawilliams5966
 
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptxArtificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
AbhijitPal87
 

How to deal with nested lists in R?

  • 1. How to deal with nested lists in R?   Using the purrr, furrr and future packages in practice. Lidia Kołakowska • Data Scientist, Sotrender Why R? 2019 Conference • Warsaw, 29.09.2019 }
  • 2. Data set ◉ Downloaded data on social issues, elections or politics ads from Facebook Ad Library API ◉ JSON-formatted response ◉ Facebook allows publish articles or research about or related to the use of the Ad Library API e.g. political advertising analysis 2
  • 3. 3 Example nested list loaded from JSON
  • 4. Nested lists ◉ Elements of list e.g. demographic_distribution are data frames – we cannot easily flatten them into a data frame ◉ Custom ids are needed for elements in nested list elements to connect them to the parent elements 4
  • 5. How to deal with data in nested list? 5
  • 7. Environment setup 7 # load necessary packages library(dplyr) library(jsonlite) library(purrr) library(fs) library(furrr) library(future) # define project path and data directory proj.dir = "/home/lkolakowska/path/to/your/project/” data.dir = proj.dir %>% paste0("data/")
  • 9. Loading data into R 9 # 1. load data from json format data.microtargeting = data.dir %>% dir_ls %>% map(~dir_ls(.x, regexp = "json")) %>% unlist() %>% map(fromJSON) %>% map("data")
  • 10. What is anonymous functions? ◉ They are used in apply() functions family ◉ In purrr packages they are user-specified, one-sided formula ◉ They have no identity and no name ◉ They will not live in the global environment 10
  • 11. Examples 11 # anonymous function syntax in purrr your.list = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] , 233, 377, 610, 987, 1597 purrr::map(your.list, ~.x * 0.75) purrr::map(your.list, function(single.element){ single.element * 0.75 })
  • 12. “ „When it’s not worth the effort to give it a name" 12 When should you use anonymous functions? Hadley Wickham
  • 13. Anonymous functions in pipe 13 # 2. add custom ids to nested data frames data.microtargeting = data.microtargeting %>% purrr::compact() %>% map(function(df) { custom_ad_id = seq( 1, nrow(df), by = 1) df = df %>% mutate(ad_id = paste0(page_id, "_", custom_ad_id)) return(df) })
  • 14. The process takes too long… 14
  • 15. Let’s parallaize software! ◉ Speed up processing ◉ Decrease memory footprint ◉ Avoid data transfer 15
  • 17. Parallization using pipe in R 17 # 3. parallaize process plan(multicore= 6) data.microtargeting = data.microtargeting %>% purrr::compact() %>% future_map(function(df) { custom_ad_id = seq( 1, nrow(df), by = 1) df = df %>% mutate(ad_id = paste0(page_id, "_", custom_ad_id)) return(df) }, .progress = TRUE)
  • 18. Summary ◉ Working with nested lists can be very efficient ◉ First perform operations on the individual elements of the list, only then combine them into one large data frame ◉ Speed up your work by performing a parallaized process 18
  • 19. Resources that made it easier to create this presentation ☺ ◉ H. Bengtsson, „Future: Parallel & Distributed Processing in R for Everyone”, eRum 2018, Budapest ◉ H. Bengtsson, „Future: Friendly Parallel Processing in R for Everyone”, SatRday Paris 2019 ◉ M. Jones, „Quick Intro to Parallel Computing in R”, 2017 ◉ L. Singham, „Anonymous Functions in R and Python”, 2017 ◉ H.Wickham, „Advanced R” - Functional programming ◉ Cool but useless, „Anonymous Functions in R - Part 1”, 2019 19
  • 20. 20 I am Lidia Kołakowska You can find me at ◉ /in/lidia-kolakowska/ ◉ /lidkol Thanks!