I am trying to keep all correlations in my correlation matrix that are above 0.7 or below -0.7. When I try using the filter_all function within dyplr, I’m always left with a data frame with 0 obs. Here is an example with a very small subset of my data. My actual data has over 40 rows & columns.
data1 <- data.frame(“Pie” = c(0.2, 0.3, 0.4), “Cake” = c(0.3, 0.6, 0.33), “Milk” = c(1, 0.2, 0.3))
data2 <- data.frame(“Pie” = c(0.11, 0.1, 0.1), “Cake” = c(0.2, 0.11, 0.02), “Milk” = c(8, 0.23, 0.37))
data_cor <- cor(data1, data2, method = "spearman")
data_cor_table <- as.data.frame(data_cor)
data_cor_table[upper.tri(data_cor_table, diag=TRUE)] = NA
data_cor_table_above <- data_cor_table %>%
filter_all(all_vars(abs(.) > 0.7))
Instead of keeping the values in my table that are -0.8660254 and 0.8660254, it is giving me a dataframe with 0 obs. Can anyone help me fix my code? Thank you!