Size Estimates By Name Apply (Loops)

This is a followup to Size Estimates by Name.

If the data on dinosaur lengths with species names is not in your working directory then download it. Import it using read.csv().

Remember the general form of the equation is:

mass <- a * length ^ b

Create a function get_mass_from_length_by_name() that takes two arguments, the length and the name of the dinosaur group. Inside this function use if/else if/else statements to check to see if the name is one of the following values and if so use the associated a and b values to estimate the species mass using these equations:

If the name is not any of these values the function should return NA.

  1. Use this function and mapply() to calculate the estimated mass for each dinosaur. You’ll need to pass the data to mapply() as single vectors or columns, not the whole data frame.

  2. Using dplyr, add a new masses column to the data frame (using rowwise(), mutate() and your function) and print the result to the console.

  3. Using ggplot, make a histogram of dinosaur masses with one subplot for each species (using facet_wrap()).

Expected outputs for Size Estimates By Name Apply: 1 2