I have a data frame with one dependent variable and 20 independent variables. I would like to find the correlation coefficients between the dependent variable and each of the independent variables and the associated p-values. I wrote the following function:
for (i in 2:20){
correl = cor.test(df[ , i], df[ , 22])
print(correl)
}
It prints out a one correlation coefficient and its p-value at a time. Is there a function that will produce the same results in a tabular format?