It doesn't need a map
as this can be done within summarise
library(dplyr)
iris %>%
summarise(out = cor(Sepal.Length, Sepal.Width, use = "complete.obs"))
# out
#1 -0.1175698
With map2
, the tasks performed are applying a function on each corresponding element of the the concerned columns, where as the cor
is on the full column taken as a single unit
The second option is doing similar one as
Map(cor, iris$Sepal.Length, iris$Sepal.Width,
MoreArgs = list(use = 'complete.obs'))
iris %>%
dplyr::select(Sepal.Length, Sepal.Width) %>%
{map2(.$Sepal.Length, .$Sepal.Width, .f = cor, use = "complete.obs")}
Or with pmap
iris %>%
dplyr::select(Sepal.Length, Sepal.Width) %>%
pmap(~ cor(.x, .y, use = "complete.obs"))
NOTE: all of them returns NA
as the number of observations are 1