Correlation/p values of all combinations of all rows of two matrices

后端 未结 4 1238
旧时难觅i
旧时难觅i 2020-12-20 04:20

I would like to calculate the correlation and the p value of that correlatio of each species (bac) to each of the factors (fac) in a second data frame. Both were measured at

4条回答
  •  既然无缘
    2020-12-20 05:07

    If you restructure your data, such that you compute correlation between paired columns, it would be super easy.

    tbac <- data.frame(t(bac))
    tfac <- data.frame(t(fac))
    
    f <- function (x, y) cor(x, y)
    
    tab <- outer(tfac, tbac, Vectorize(f))
    
    as.data.frame.table(tab)
    

    I had an answer using the same idea: Match data and count number of same value.

提交回复
热议问题