Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

correlation at the end of a pipe operation

Tags:

r

purrr

I am trying to get a correlation between two variables at the end of a pipe operation, why don't these work?

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"))

thanks

like image 589
user63230 Avatar asked Oct 15 '25 16:10

user63230


1 Answers

Don't forget about %$% !

library(magrittr)

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

Created on 2021-03-02 by the reprex package (v0.3.0)

like image 91
tomasu Avatar answered Oct 18 '25 09:10

tomasu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!