xx <- data.frame(group = rep(1:4, each=100), a = rnorm(100) , b = rnorm(100))
xx[c(1,14,33), 'b'] = NA
I'm trying to calculate correlations by group but I'm getting an error when there are NAs.
library(dplyr)
xx %>% group_by(group) %>% summarize(COR=cor(a,b,na.rm=TRUE))
Error: Problem with `summarise()` column `COR`.
i `COR = cor(a, b, na.rm = TRUE)`.
x unused argument (na.rm = TRUE)
i The error occurred in group 1: group = 1.
Run `rlang::last_error()` to see where the error occurred.