In R, correlation test between two columns, for each of the groups in a third column

后端 未结 2 1093
渐次进展
渐次进展 2021-01-07 15:10

My data frame (g) contains 2 columns with continues data and other columns with categorical data. I want to test for correlations between the 2 continues variables, in diffe

2条回答
  •  没有蜡笔的小新
    2021-01-07 15:43

    If I understand right, you want to compute the correlations between GDW and GN for every value in the column M1 (that is, by splitting at every unique value of M1).

    Using Hadley's plyr

    require(plyr)
    # assuming the data.frame is df (Note: factor M1 if necessary)
    daply(df, .(M1), function(y) cor(y$GDW, y$GN))
    

提交回复
热议问题