Note that order of operations is important in writing R code.
4 - 2 ^ 2
(4 - 2) ^ 2
5 * 2 - 3 ^ 2
! TRUE & pi == 3
! (TRUE | FALSE)
Evaluate all four expressions. Note !
is R’s not operator.
Document this function with
RollDice <- function(num.rolls){
#
# ARGS:
# RETURNS:
return(sample(6, num.rolls, replace = T))
}
Note for help with functions in R, type ?sample
.
Use the defined style guidelines to create an R script that:
Verify your functions works by running it twice using “MT” and “NE” as inputs.
Now write a function that;
Also include and the stop()
function for errors. Test this function with two settings:
Earlier we wrote a function to compute the average housing price for two states, now use aggregate to compute this for all the states in the housing data set.