Q:

Write a R program to create a correlation matrix from a dataframe of same data type

0

Write a R program to create a correlation matrix from a dataframe of same data type.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

d = data.frame(x1=rnorm(5),
               x2=rnorm(5),
               x3=rnorm(5))
print("Original dataframe:")   
print(d)
result = cor(d) 
print("Correlation matrix:")
print(result)

Sample Output:

[1] "Original dataframe:"
          x1         x2         x3
1 -0.0905430  1.7469241 -0.1360780
2 -0.1936120  0.9111132  0.5282113
3  0.7688536 -0.9413734 -0.8032169
4  2.0247769 -0.3096149 -0.8617996
5 -0.1824352  1.6179504 -0.2554897
[1] "Correlation matrix:"
           x1         x2         x3
x1  1.0000000 -0.7422855 -0.7789883
x2 -0.7422855  1.0000000  0.6600909
x3 -0.7789883  0.6600909  1.0000000

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now