Perform the following steps:
- Here, you can get the covariance matrix by inputting the first three variables in mtcars to the cov function:
> cov(mtcars[1:3])
Output:
mpg cyldisp
mpg 36.324103 -9.172379 -633.0972
cyl -9.172379 3.189516 199.6603
disp -633.097208 199.660282 15360.7998
- To obtain a correlation matrix of the dataset, we input the first three variables of mtcarsto the cor function:
> cor(mtcars[1:3])
Output:
mpg cyldisp
mpg 1.0000000 -0.8521620 -0.8475514
cyl -0.8521620 1.0000000 0.9020329
disp -0.8475514 0.9020329 1.0000000