Hi, I want to write a function, in which I can select any variables from different data frames (tibbles) and which will return the coefficients in a vector form. For example, this is my data frame:

df1 <- tibble(a=rnorm(10), b=rnorm(10), c=rnorm(10), d=rnorm(10))

df2 <- tibble(x1=rnorm(10), x2=rnorm(10), x3=rnorm(10), x4=rnorm(10))

df3 <- tibble(y1=rnorm(10), y2=rnorm(10), y3=rnorm(10), y4=rnorm(10))

And these are my suggested correlation tests (only a part of it):

cor(df1$a, df2$x1)

cor(df1$a, df2$x2)

cor(df1$a, df2$x3)

cor(df1$a, df2$y1)

cor(df1$a, df2$y2)

cor(df1$a, df2$y3)

cor(df1$b, df2$x1)

cor(df1$b, df2$x2)

cor(df1$b, df2$x3)

cor(df1$b, df2$y1)

cor(df1$b, df2$y2)

cor(df1$b, df2$y3)

How can I write a function so that I can specify the first group of variables in a vector (say x),

and specify the second group of variables in another vector (say y), and then get the results of cor(x,y) which will give all the suggested correlation coefficients in a vector?

Any alternative solutions would also be appreciated.