0

I'm trying to use "rcorr" function with my data , but the problem is that it works only with matrix. That's why I do convertation from data.frame to matrix:

my.data <- as.matrix(my.data)

and it comes to matrix, but when I type "typeof" it shows

typeof(my.data)

[1] "character"

So, "rcorr" gives me an error

Error in rcorr(my.data, type = "spearman") : 


 NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In storage.mode(x) <- "double" : NAs introduced by coercion

Can anyone tell me what is wrong? Thank you!

Melissa J.
  • 15
  • 6
  • `mode(my.data) = "numeric"` will work assuming everything is coercible to numeric. (Do this after the `as.matrix` conversion.) – Gregor Thomas Nov 09 '17 at 21:28
  • can you show us the results of `str(my.data)` ... ? – Ben Bolker Nov 09 '17 at 21:34
  • Possible dupes: [Right way to convert data.frame to numeric matrix when data frame also contains strings](https://stackoverflow.com/q/16518428/903061), or if string removal isn't an issue, [Convert character matrix into numeric matrix](https://stackoverflow.com/q/20791877/903061). – Gregor Thomas Nov 09 '17 at 21:37
  • str(my.data) num [1:5142, 1:32] 2 2 2 2 2 2 2 2 2 2 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:5142] "1" "2" "3" "4" ... ..$ : chr [1:32] "patient_N" "age" "group" "BG_fasting" ... – Melissa J. Nov 09 '17 at 21:55

0 Answers0