trouble with calculation of correlation

Hi all,

I should like to ask your help about a calculate line of my script.
I would like to calculate, for each line of a dataframe called "test_AE33", a correlation coefficient (r²) between :

  1. c( dataframe$column1, dataframe$column2,..., dataframe$column7)
  2. c (370, 470, 525, 590, 660, 880, 940) (constant values)
    I try to apply that thanks to this line :
    test_AE33$r_carre = round(cor( c(test_AE33$babs1, test_AE33$babs2, test_AE33$babs3, test_AE33$basb4, test_AE33$basb5, test_AE33$basb6, test_AE33$basb7), c(370, 470, 525, 590, 660, 880, 940), use = "complete.obs"), 2)
    But RStudio answer is : "Error in cor(c(test_AE33$babs1, test_AE33$babs2, test_AE33$babs3, test_AE33$basb4, :
    dimensions incompatibles"
    Though, we have the same number of canstants than columns...

Some ideas?
Thanks for your help !

Hi @pabpab,

it is a bit unclear what you are trying to achieve. Are you trying to calculate correlation between (for example) test_AE33$babs1 and 370? Correlation is a measure of co-movement between 2 random variables, not a random variable and a constant - so you might need to reconsider what you are trying to achieve.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.