My name is Roman and I'm new to this group. I'm working with the mtcars dataset and was wondering how to get correlations for multiple variables by group using tidyverse functions. For example, I can get correlations for two variables like below, but I don't know how to do it for more than two or even all the variables in the dataset.
I'd like to be able to see correlations for any number of selected variables by group i.e. if I wanted to see the correlation stats between mpg, wt, and disp grouped by cyl for example.
mtcars %>% group_by(cyl) %>% summarise(cor = cor(mpg, wt)) #> # A tibble: 3 x 2 #> cyl cor #> <dbl> <dbl> #> 1 4 -0.7131848 #> 2 6 -0.6815498 #> 3 8 -0.6503580
Thanks all for your time and help.