I would like a correlation table only for my two main variables, but with more than ten other parameters. Here is the thing in Python table python. I would like to do the same thing in R, but I only manage to have a big matrix 12*12. I just want to select 2 variables. Do you think it is possible?
Asked
Active
Viewed 81 times
0
-
1It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Aug 25 '22 at 14:26
1 Answers
0
cor
will create the whole correlation matrix, and you can select the two variables you want to display by indexing their columns.
This is a very basic example.
cor(mtcars)[, c("mpg", "cyl")]
#> mpg cyl
#> mpg 1.0000000 -0.8521620
#> cyl -0.8521620 1.0000000
#> disp -0.8475514 0.9020329
#> hp -0.7761684 0.8324475
#> drat 0.6811719 -0.6999381
#> wt -0.8676594 0.7824958
#> qsec 0.4186840 -0.5912421
#> vs 0.6640389 -0.8108118
#> am 0.5998324 -0.5226070
#> gear 0.4802848 -0.4926866
#> carb -0.5509251 0.5269883
Created on 2022-08-25 by the reprex package (v2.0.1)
If you want to do more manipulation with it, you might want to take an extra step to coerce this matrix to tibble
with the rownames
argument so you get those variable names into a column instead of a rowname.

Arthur
- 1,248
- 8
- 14
-
In fact I would have liked something visual, as the corrplot function allows, but only by presenting 2 variables. The corrplot function returns the whole matrix unfortunately – lunae_majicam Aug 25 '22 at 14:37
-
OK. I recommend asking a new question then. This one has been around for a few days, and the title and first post ask for a table, not a plot. – Arthur Aug 29 '22 at 12:02