The multiplier =
argument is a little silly. Let’s just give one option to make it a percentage.
TRUE
and FALSE
are special terms in R (no quotes)
Let’s say we want to replace the multiplier =
argument with percentage =
, where the user can set TRUE
or FALSE
.
TRUE
/FALSE
lead naturally to if
statements[1] 0.6
[1] 60
[1] 0.6
[1] 51.78423
if
statements to check if the vector has only one (or fewer) elements and return NA
if so. (Hint: the length()
function will be helpful!) You don’t need any extra arguments besides the vector of numbers.sd(x)=√∑ni=1(xi−ˉx)2n−1
Modify your function to remove the NA values before calculating the standard deviation. (Hint: the na.omit()
function will be helpful!) Add an argument na.rm =
that defaults to TRUE
(the opposite of the na.rm
argument in the built-in R function sd()
). If na.rm = FALSE
, then the function should return NA
if there are any NA values in the vector.
What is the standard deviation of income in (all of) NLSY? Compare with the built-in R function sd()
.