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.

groups. (This function is part of the lattice package you use in Chapter 17.)Using the formula interface, you can plot two histograms in Figure 15-1 atonce using the following code:> library(lattice)> histogram(~temp | factor(activ), data=beaver2)Figure 15-1: Plotting histograms for different groups.You find more information about the formula interface in Chapter 13, but let’sgo over this formula once more. The histogram() function uses a one-sidedformula, so you don’t specify anything at the left side of the tilde (~). On the rightside, you specify the following:Which variable the histogram should be created for: In this case, that’sthe variable temp, containing the body temperature.After the vertical line (|),the factor by which the data should be split: Inthis case, that’s the variable activ that has a value 1 if the beaver was activeand 0 if it was not. To convert this numeric variable to a factor, you use thefactor() function.The vertical line (|) in the formula interface can be read as “conditional on.”It’s used in that context in the formula interfaces of more advanced statisticalfunctions as well.Using quantile plots

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

Saved successfully!

Ooh no, something went wrong!