-1

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

Jack
  • 165
  • 2
  • 12
  • 1
    Your 'x' and 'y' can be either `vector` or `matrix`. Check if that is the case. Without a reproducible example, it is hard to know what is going on. – akrun Oct 29 '15 at 04:16

2 Answers2

0

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.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487
-1

There must be some categorical variable in X.So you can first separate that categorical variable from X and then use X in cor() function.

Pankaj Sharma
  • 388
  • 7
  • 18