Exercises

  1. We are given the following list:

    One way to access the letter “b” in the first element of lst is as follows:

    ## [1] "b"

    Another way is:

    ## [1] "b"
    For each of the following objects, find at least two ways to access it within lst:
    • the vector of letters from “c” to “j”;
    • the capital letter “F”;
    • the vector of numbers from 1 to 10;
    • the heights of the five tallest individuals in m111survey.
  2. Write a function called goodStats() that, when given a vector of numerical values, computes the mean, median and standard deviation of the values, and returns these values in a list. The function should take two parameters:
    • x: the vector of numerical values;
    • ...: the ellipses, which allow the user to pass in additional arguments.
    The list returned should name each of the three quantities:
    • the name of the mean should be mean;
    • the name of the standard deviation should be sd;
    • the name of the median should be median.

    Typical examples of use should look like this:

    ## $mean
    ## [1] 3
    ## 
    ## $sd
    ## [1] 1.581139
    ## 
    ## $median
    ## [1] 3
    ## [1] 7.5