Q: R Correlation between factored variables I am wondering if there is an easy way to identify character/factor variables that are 100% correlated with another variable. So, in the example, the process would match 'color' and 'vehicle' as well as 'plant' and 'height'
color <- c('black', 'black', 'blue', 'blue', 'yellow')
vehicle <- c('truck', 'truck', 'car', 'car', 'bike')
plant <- c('tree', 'flower', 'grass', 'tree', 'flower')
height <- c('tall', 'medium', 'short', 'tall', 'medium')

df <- as.data.frame(cbind(color, vehicle, plant, height))

Currently, I get the level number of the factors and run a correlation matrix and pull out the pairs that have a correlation of 1 (other than the self pairs). 
The package compare works: 
library(tidyverse)
library(compare)

f <- function(x) factor(x, levels= unique(x))

f.df <- as.tibble(df) %>%
  mutate_if(is.character, f) %>%
  mutate_if(is.factor, as.numeric) 

compare(f.df$color, f.df$vehicle)
compare(f.df$color, f.df$plant)

To get the correlations to test:
cor <- cor(f.df)

cor[lower.tri(cor)] <- 0

vars.corr <- data.frame(cor) %>%
  mutate(var1= rownames(.)) %>%
  select(var1, everything()) %>%
  gather(var2, val, -var1) %>%
  filter(var1!= var2) %>%
  filter(val > .99)

But I'm struggling with applying the compare function using map (purrr) to iterate over the pairs of variables (var1 and var2 in vars.corr), or writing a function and applying enquo properly to read in the variables from the list and apply to f.df.
But this seems like a rabbit hole now and I'm thinking surely there is an easier way!
Thanks for any suggestions!

A: For the individual pairs:
perfect_cor <-   function (var1, var2) {
  all(rowSums(as.matrix(table(df[[var1]], df[[var2]])) > 0) == 1)
}
perfect_cor <- Vectorize(perfect_cor) # necessary for using `outer`

To apply this over all pairs:
outer(names(df), names(df), perfect_cor)

