Multiple correlation with R I have a data frame presenting different variables in column and for different species name in rows as follow. In the column a have only one independent variables(Proteome size) and all the others are independent variables. I want to use the PIC package to correlate all these dependent variables separately to my independent variables, a way to generate the R coefficient and p-value.

data &lt;- read.table("t1.txt", row.names = 1, header = T,sep='')

data 
path1 path2 path3 path4 Proteome_size
ahli 4.0 -3.2 0.4 -1.0 -0.2
alayoni 3.8 3.4 -1.8 2.2 -0.3
alfaroi 3.5 2.6 0.8 -2.4 -0.5
aliniger 4.0 0.1 -1.7 2.4 0.0
allisoni 4.4 2.0 -3.7 0.5 -0.1
allogus 4.0 -2.8 0.6 -1.0 0.6
altitudinalis 3.8 2.9 -6.1 2.3 1.2
alumina 3.6 0.7 1.5 -2.7 -1.3
alutaceus 3.6 1.2 -0.6 -1.7 0.3
angusticeps 3.8 4.6 -2.0 1.2 1.7


I have this code following code that can correlate any one of the ‘path*’ column to proteome size:

data &lt;- read.csv("data.csv", row.names = 1
tree &lt;- read.tree("anolis.phy")
Proteome &lt;- data[, "Proteome_size"]
awe &lt;- data[, "path1"]
names(Proteome_size) &lt;- names(var1) &lt;- rownames(data)
hPic &lt;- pic(proteome_size, tree)
aPic &lt;- pic(gene1, tree)
picModel &lt;- lm(hPic ~ aPic - 1)
summary(picModel)


My question is that, how can I implement this code to do that for all the columns simultaneously and store the statistics info as (R and p_value) for each variable somewhere ?

Thanks
One option is to use one of the apply family functions. If you enclose your code above (which generates errors by the way) in a function, you can then "apply" this function on the rows or columns of your data with something like apply(X, MARGIN, FUN, …), the margin being 1 for rows or 2 for columns (as in your case).