Exercises
We are given the following list:
<- list(yabba = letters, lst dabba = list(x = LETTERS, y = 1:10), do = bcscr::m111survey)
One way to access the letter “b” in the first element of
lst
is as follows:$yabba[2] lst
## [1] "b"
Another way is:
1]][2] lst[[
## [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
.
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:
<- 1:5 vec goodStats(x = vec)
## $mean ## [1] 3 ## ## $sd ## [1] 1.581139 ## ## $median ## [1] 3
<- c(3, 7, 9, 11, NA) vec <- goodStats(x = vec, na.rm = TRUE) myStats $mean myStats
## [1] 7.5