Skip to content

Instantly share code, notes, and snippets.

@szimmer
Created January 21, 2021 14:30
Show Gist options
  • Save szimmer/629d8c846ead6fde8f6fefc4fac23a0b to your computer and use it in GitHub Desktop.
Save szimmer/629d8c846ead6fde8f6fefc4fac23a0b to your computer and use it in GitHub Desktop.
pmap example with constant second argument
library(tidyverse)

x <- list(1, 2, 3)
y <- list(3, 3, 3)
z <- list(100, 200, 300)

j <- function(first, second, third) (first + third) * second


pmap(list(x, z), j, second=3)
#> [[1]]
#> [1] 303
#> 
#> [[2]]
#> [1] 606
#> 
#> [[3]]
#> [1] 909

pmap(list(x, y, z), j)
#> [[1]]
#> [1] 303
#> 
#> [[2]]
#> [1] 606
#> 
#> [[3]]
#> [1] 909

Created on 2021-01-21 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment