12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ow has Sepal.Width on the x-axis and Petal.Length on the y-axis.When the plot() function notices that you pass a data frame as anargument, it calls the pairs() function to create the plot matrix. This functionoffers you a lot more flexibility. For example, on the Help page ?pairs, youfind some code that adds a histogram on the diagonal plots. Check out theexamples on the Help page for some more tricks.Figure 14-4: Plotting the relations for all variables in a dataset.Getting the numbersThe amount in which two variables vary together can be described by thecorrelation coefficient. You get the correlations between a set of variables in R veryeasily by using the cor() function. You simply add the two variables you want toexamine as the arguments. For example, if you want to check how much the petalwidth correlates with the petal length, you simply do the following:> with(iris, cor(Petal.Width, Petal.Length))[1] 0.9628654This tells you that the relation between the petal width and the petal length isalmost a perfect line, as you also can see in the fourth plot of the third row inFigure 14-4.Calculating correlations for multiple variables

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!