Homework 2: Data


Send me an email containing an .R file with the code for the following tasks. Use comments in the code to describe and explain.

Please check the syllabus for the correct file naming convention and for the correct subject line in your email. Practice being precise!

Follow the style guidelines I provided.

Read data

Create a data frame from the oak water potential data I have posted at http://r-research-tool.schwilk.org/lectures/data/oak-water-potentials-simple.csv. Use

oak_wp <- read.csv("http://r-research-tool.schwilk.org/lectures/data/oak-water-potentials-simple.csv",
         stringsAsFactors = FALSE)

These data provide water potential (a measure of plant water status/stress) for multiple individuals of several oak species in the Davis Mountains of west Texas. A quick description of the variables (columns):

a three-letter code indicating the site location
the tree tag, a unique identifier for each tree (a string)
a four letter code indicating species (see http://plants.usda.gov/)
The date of data collection (as a string in format MM/DD/YY)
pre-dawn water potential (numeric)
mid-day water potential (numeric)
year of measurement as an integer

Note that you can access a column of data in a data frame by name. For example, to obtain the vector of all tags:


Answer the following questions

Write code to answer these questions and provide the answers in comments.

  1. How many different species are recorded in these data?
  2. Mid day water potential should always be at least as negative as pre-dawn water potential. Are there any days and plants for which mid-day water potential is higher than pre-dawn?
  3. What is the lowest (most negative) mid-day water potential in this data set? When and for which species was this value recorded? Hint: see the which.min() function
  4. For which year was the average mid day water potential lowest (most negative)?
Back to top | E-mail Schwilk