Search code examples
rcorrelationstat

correlation of several columns need to be calculated


I'm trying to get the correlation coefficient for corresponding columns of two csv files. I simply use the followings but get errors. consider each csv file has 50 columns

      first values <- read.csv("")
      second values <- read.csv("")
       correlation.csv <- cor(x= first values , y=second values, method="spearman)

But i get x' must be numeric error! subset of one csv file

Thanks for your help


Solution

  • The read.table function and all of it's derivatives return a data.frame which is an R list object. The mapply function processes lists in "parallel". If the matching columns are in the same order in the two datasets and have the same number of rows and do not have spaces in their names, it would be as simple as:

     mapply(cor, first_values , second_values)
    

    If it's more complicated tahn that, then you need to fill in the missing details with example data by editing the question (not by responding in comments.)