简体   繁体   中英

Finding correlation with p-value in R using Hmisc package

I am trying to find the correlation between variables of a dataframe in R. My head of the dataframe is below.

> head(datafile)

  Taxon   Petals Internode    Sepal    Bract  Petiole     Leaf    Fruit
1     I 5.621498  29.48060 2.462107 18.20341 11.27910 1.128033 7.876151
2     I 4.994617  28.36025 2.429321 17.65205 11.04084 1.197617 7.025416
3     I 4.767505  27.25432 2.570497 19.40838 10.49072 1.003808 7.817479
4     I 6.299446  25.92424 2.066051 18.37915 11.80182 1.614052 7.672492
5     I 6.489375  25.21131 2.901583 17.31305 10.12159 1.813333 7.758443
6     I 5.785868  25.52433 2.655643 17.07216 10.55816 1.955524 7.880880

The code I'm using to find the data frame is below

#correlation
install.packages("Hmisc")
library(Hmisc)
rcorr(as.matrix(datafile))

I'm getting the following error when i tried that.

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

kindly help.

Yes, Just like the comment said. I had to exclude the variable Taxon, which is not numeric.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM