Exercises: Writing functions

  1. Write a function to calculate the mean of a series of numbers. Compare the answer to the built in R function.

  2. Write a function that prints out the mean and standard deviation of a series of numbers.

  3. Modify the above function to include standard error (=SD/sqrt(sample size))

  4. Write a function to convert Fahrenheit to Celsius. What is 80F in C? What is 40F in C? (hint: C = (F-32)*(5/9))

  5. Write a function to calculate the species richness (number of species) of each transect of the species-counts.txt file that contains data on the number of individuals of each species found in each transect.

  6. Write a function to calculate the Simpson diversity index where pi is the fraction of all organisms which belong to the i-th species. Calculate the Simpson index for each transect using the same data.

  1. Make a pretty plot of Simpson index vs. species richness.