-3

i have database in excel i need to calculate the correlation betwen all variables in my database and after do graphique i need to know how do that using R i use :

 M<-cor(Donn2[,-1])
> M
                          Litrage produit Rapportinjection      Format Nbre passage eau
Litrage produit                 1.0000000       0.20415852  0.27658465       0.67426686
Rapportinjection                0.2041585       1.00000000 -0.12380173       0.31795429
Format                          0.2765846      -0.12380173  1.00000000      -0.05253294
Nbre passage eau                0.6742669       0.31795429 -0.05253294       1.00000000
Pertes totales PF(%)           -0.5233907      -0.07581707 -0.52733899      -0.22555675
Pertes PF secteur 3 (eur)              NA               NA          NA               NA
Coût pertes Secteur 3 (L)       0.6742669       0.31795429 -0.05253294       1.00000000
                          Pertes totales PF(%) Pertes PF secteur 3 (eur) Coût pertes Secteur 3 (L)
Litrage produit                    -0.52339068                        NA                0.67426686
Rapportinjection                   -0.07581707                        NA                0.31795429
Format                             -0.52733899                        NA               -0.05253294
Nbre passage eau                   -0.22555675                        NA                1.00000000
Pertes totales PF(%)                1.00000000                        NA               -0.22555675
Pertes PF secteur 3 (eur)                   NA                         1                        NA
Coût pertes Secteur 3 (L)          -0.22555675                        NA                1.00000000

i have some value with NA what that mane is just in one variable when i have NA

and when i use ;

> corrplot(M, type="upper")

i have coorgrame i have something like that :

enter image description here

why i get result like that with value NA ?

thank you

Sarah Tohami
  • 59
  • 1
  • 12
  • Maybe you can checkout this [post](https://stackoverflow.com/questions/22282531/how-to-compute-correlations-between-all-columns-in-r-and-detect-highly-correlate). It's using correlation matrix in R. – Huan Sep 18 '19 at 22:01
  • 1
    It is difficult to understand the data with a screenshot. Can you add `dput(df)` to your question ? – Ronak Shah Sep 19 '19 at 02:54
  • okey that what i i had when i do dput(df) – Sarah Tohami Sep 19 '19 at 09:41

1 Answers1

1

By excluding all character and factor variables you could use cor() function. Here, an example using iris dataset

data(iris)
cor(iris[,-5])
Duck
  • 39,058
  • 13
  • 42
  • 84
  • In the case of your dataset you should exclude first column `cor(YourData[,-1])` – Duck Sep 18 '19 at 22:02
  • thank you but when i do cor(Donn[,-1]) i had error like Error in cor(Donn[, -1]) : 'x' should be numeric – Sarah Tohami Sep 18 '19 at 22:17
  • 1
    @SarahTohami Try `str(Donn)` and check other variables that can be character, then remove it in a style of `cor(Donn[, -c(1,index_of_your_variable)])` – Duck Sep 19 '19 at 13:26
  • all is okey but i have value NA in one variable i will edit my question thank you – Sarah Tohami Sep 19 '19 at 14:10
  • i edited my question with problem value NA how can i fixe the problem please ? thank you – Sarah Tohami Sep 19 '19 at 14:17
  • 1
    @SarahTohami In your case you should use something like this `cor(iris[,-5],use = "complete.obs")` where `complete.obs` allows to only consider those observations with values different from `NA`. Hoping this helps! – Duck Sep 19 '19 at 17:22
  • that good , i have question please the values that i get when i calculate correlation M<-corr .... theey mean the degre of correlation betwen the variables ? or what thank you – Sarah Tohami Sep 19 '19 at 17:40
  • i have question what is the test we use here ? – Sarah Tohami Sep 19 '19 at 18:31
  • 1
    @SarahTohami Correlation is a measure of level of association, the closest to 1 is, the most positive relationship and the closest to -1 is, the most negative relationship. You can test significance of correlation using normal approach. Hope this helps. – Duck Sep 20 '19 at 22:01