首页 > 解决方案 > 管道操作结束时的相关性

问题描述

我试图在管道操作结束时获得两个变量之间的相关性,为什么这些不起作用?

library(tidyverse)
iris %>% 
  map(~cor(.$Sepal.Length, .$Sepal.Width, use = "complete.obs"))

#or
iris %>% 
  dplyr::select(Sepal.Length, Sepal.Width) %>% 
  map2(~cor(.x, .y, use = "complete.obs"))

谢谢

标签: rpurrr

解决方案


别忘了%$%

library(magrittr)

iris %$% 
  cor(Sepal.Length, Sepal.Width, use = "complete.obs")
#> [1] -0.1175698

reprex 包(v0.3.0)于 2021-03-02 创建


推荐阅读