0

My data frame = epa201 I have three numeric columns: x, y, and z

what could be code to make correlation matrix and correlation among these three variables in R programming

I wrote:

corpmat (<-cor[,x, y, z])
corrplot(cormat)

but got wrong.

  • 1
    In R, `[` is used for subsetting. So `cor[,x, y, z]` is trying to subset the `cor` function. You want to subset your data, not the function. (And use your data in your code.) `cormat <- cor(epa201[, c("x", "y", "z")])`. You also have a typo, `corpmat` in the first line does not match `cormat` in the second line - make sure you use the same names consistently. – Gregor Thomas Nov 08 '22 at 02:15
  • Yes, your help works: cormat <- cor(epa2021[, c("engine_displacement", "no_cylinders", "no_gears", "comb_mpg")]) corrplot::corrplot(cormat, ) I finally wrote the above code for my data. – abraham Nov 08 '22 at 15:26

0 Answers0