Correlation problems in Rstudio

You will need to provide more information, preferably a reprex, to provide any help.

In general, if you want to get a correlation matrix, it is really simple using the cor function.

# setting seed
set.seed(seed = 23493)

# generating random data
x1 <- runif(n = 100)
x2 <- rnorm(n = 100)
x3 <- rcauchy(n = 100)
x4 <- rexp(n = 100)
x5 <- rlogis(n = 100)

# combining to get a dataset of 5 columns
d <- data.frame(x1,
                x2,
                x3,
                x4,
                x5)

# finding correlation matrix
(r <- cor(x = d))
#>              x1           x2          x3           x4           x5
#> x1  1.000000000  0.005969777  0.04610351  0.080191762 -0.090464853
#> x2  0.005969777  1.000000000  0.14000817 -0.027236185 -0.094456667
#> x3  0.046103509  0.140008173  1.00000000  0.056563325 -0.080159816
#> x4  0.080191762 -0.027236185  0.05656333  1.000000000 -0.008438071
#> x5 -0.090464853 -0.094456667 -0.08015982 -0.008438071  1.000000000

Created on 2019-02-10 by the reprex package (v0.2.1)

1 Like