Does calculating correlation between two dataframes require a loop?

前端 未结 3 1465
臣服心动
臣服心动 2020-12-11 02:15

I have a set of large dataframes that look like A and B:

A <- data.frame(A1=c(1,2,3,4,5),B1=c(6,7,8,9,10),C1=c(11,12,13,14,15 ))

  A1 B1 C1
1  1  6 11
2          


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 02:43

    Another alternative you can use mapply function

    > mapply(function(x,y) cor(x,y),A,B)
           A1        B1        C1 
    0.9481224 0.9190183 0.4595880 
    

    Or just mapply(cor, A, B) as suggested by @Aaron.

提交回复
热议问题