---
title: 'R for Researchers: Data exploration solutions'
date: "April 2015"
---
This article contains solutions to exercises for an article in the
series R for Researchers.
For a list of topics covered by this series, see the
[Introduction](RFR_Introduction.html) article.
If you\'re new to R we highly recommend reading the articles in order.
There is often more than one approach to the exercises.
Do not be concerned if your approach is different than
the solution provided.
These solutions require the solutions from the prior lesson be
run in your R session.
```{r, echo=FALSE, results="hide", message=FALSE, warning=FALSE}
source("Scripts/RFR_alfalfa_DP.R")
```
#### Exercise solutions
These exercises use the alfalfa dataset and the work
you started on the alfAnalysis script.
Open the script and run all the commands in the script
to prepare your session for these problems.
1. Do a summary of the alfalfa data.frame.
```{r, comment=NA }
summary(alfalfa)
```
2. Do a cor of the shade, irrig, and yield variables.
Use only the variables which have a sensible order.
```{r, comment=NA }
cor(alfalfa[,-c(3,5)])
```
3. Create a frequency table for shade and irrig.
```{r, comment=NA }
table(alfalfa$shade,alfalfa$irrig)
```
4. Use aggregate to find the mean of the inoculate groups.
```{r, comment=NA }
aggregate(alfalfa$yield, by=list(alfalfa$inoc),FUN=mean)
```
5. Commit your changes to AlfAnalysis.
There is no code associated with the solution to this problem.
6. Use plot to create pairwise plots for the alfalfa data.frame.
```{r, comment=NA }
plot(alfalfa)
```
7. Use ggplot to plot to create a scatter plot of the
yield vs\. inoc.
Use a white background and color the observations
based on shade level.
```{r, comment=NA }
ggplot(alfalfa) +
geom_point(aes(x=inoc, y=yield, color=shadeLev)) +
theme_bw()
```
8. Commit your changes to AlfAnalysis.
There is no code associated with the solution to this problem.
Return to the [Data exploration](RFR_DataExpl.html) article.
Last Revised: 2/9/2015