I'm trying to create matrices of various distance/association functions in R. I have a function similar to cor that gives the association between two vectors. Now I want to take a dataframe (or matrix) of numeric vectors, something like mtcars, and create a matrix from the function and data frame. I thought this is what outer is for but am not getting it to work. Here's an attempt using cor and mtcars.
cor(mtcars$mpg, mtcars$cyl) #a function that gives an association between two vectors
outer(mtcars, mtcars, "cor") #the attempt to create a matrix of all vectors in a df
Yes I know that cor can do this directly, let's pretend it can't. that cor just finds correlations between two vectors.
So the final goal would be to get the matrix you get from cor(mtcars).
Thank you in advance.