Error in cor.test.default(data[, i], data[, j], na.rm = T)

I want to analyze the relations with corrigraph() of the package {KefiR}

y data are "etude"

> etude
# A tibble: 27 × 6
   resveratrol viniferine vitisine sol      porte.greffe   age
         <dbl>      <dbl>    <dbl> <chr>    <chr>        <dbl>
 1        26.5       146.     41.5 Calcosol RSB              4
 2        26.5       150.     43   Calcosol RSB              4
 3        26         144.     41   Calcosol RSB              4
 4        53         418      46   Calcosol RSB             16
 5        52.5       420.     46   Calcosol RSB             16
 6        52.5       420.     46   Calcosol RSB             16
 7        76.5       414       8   Calcosol RSB             49
 8        77         415       8   Calcosol RSB             49
 9        78         422.      7.5 Calcosol RSB             49
10        44.5       334.      8.5 Calcosol 1103 P          39

corrigraph(etude,mu=TRUE, prop=TRUE)

And in return I have

na omit          porte.greffe
sol        1103 P Fercal Gravezac RSB
  Calcosol      6      3        3   9
  Planosol      3      0        0   0
  Rendosol      3      0        0   0
na omit            sol
porte.greffe Calcosol Planosol Rendosol
    1103 P          6        3        3
    Fercal          3        0        0
    Gravezac        3        0        0
    RSB             9        0        0

cor calculation
================================================== 
============Error in cor.test.default(data[, i], data[, j], na.rm = T) : 
  'x' doit être un vecteur numérique

I don't understand how to adjust my matrix, can you please help me? Thanks :slight_smile:

Hello,
To calculate correlation you must supply numeric vectors of the same length. However, you can search for documentation of the function cor.test(). You can find the first argument in the documentation as follows (to calculate the correlation between x and y).

Arguments

x, y : numeric vectors of data values. x and y must have the same length.
#-----------------------
Two of the columns sol and porte.greffe in your etude data are character vectors not numeric. you must remove them before applying cor.test() or other functions that uses cor.test()in the backend. You can do simply;

# For few columns
etude_num <- etude[, !colnames(etude) %in% c("sol", "porte.greffe")]
# For more general case with numbers of columns
library(tidyverse)
etude_num <- edute %>%
   dplyr::select_if(is.numeric)
# Finally apply your desire functions
corrigraph(etude_num, mu = TRUE,  prop = TRUE)
1 Like

Hello Ringku09,

Thank you very much for your help.

I have try your suggestion, here is what it says

> # For few columns
> etude_num <- etude[, !colnames(etude) %in% c("sol", "porte.greffe")]
> # For more general case with numbers of columns
> library(tidyverse)
> etude_num <- edute %>%
+   dplyr::select_if(is.numeric)
Error in tbl_vars_dispatch(x) : object 'edute' not found
> etude_num <- etude %>%
+   dplyr::select_if(is.numeric)
> # Finally apply your desire functions
> corrigraph(etude_num, mu = TRUE,  prop = TRUE)

cor calculation
================================================== 
============Error in cor.test.default(data[, i], data[, j], na.rm = T) : 
  'x' doit être un vecteur numérique
> # For few columns
> etude_num <- etude[, !colnames(etude) %in% c("sol", "porte.greffe")]
> # For more general case with numbers of columns
> library(tidyverse)
> etude_num <- etude %>%
+   dplyr::select_if(is.numeric)
> # Finally apply your desire functions
> corrigraph(etude_num, mu = TRUE,  prop = TRUE)

cor calculation
================================================== 
============Error in cor.test.default(data[, i], data[, j], na.rm = T) : 
  'x' doit être un vecteur numérique

So once again it says that x must be a numeric vector. But when I see the data, everything is numeric.. :confused:

What should I do ? :pray:

Hi,
sorry for being delay to reply. please load the data first
Look at the first error message: Error in tbl_vars_dispatch(x) : object 'edute' not found.
There is no data named etude in your current environment.

1 Like

Hi,

Thank you for your answer.

This name object mistake has been corrected but still I have the error message cor calculation

==========Error in cor.test.default(data[, i], data[, j], na.rm = T) :
'x' doit être un vecteur numérique

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.