Session 8
September 26, 2024
# Defining a function
# a_function will be the name of the function
# arguments go within the ()
# code goes in the curly braces
a_function <- function(an_argument) {
# code using an_argument to produce final_output
# whatever is inside return() comes out of the function
return(final_output)
}
# Run the code to create the function
# Then you can use it:
# a_function(<some_input>)
#
Write a function to convert metric to imperial measurements.
source(<path_to_functions_script>)
in your main script.Save our function in a separate R script and source it from a data wrangling script.
TRUE
or FALSE
if(<condition>) {
<action to take if TRUE>
}
if(<condition>) {
<action to take if TRUE>
} else {
<action to take if FALSE>
}
==
for “is equal to”!=
for “not equal to:<
, >
for less than/greater than<=
, >=
for less than or equal to/greater than or equal tois.na()
for is it NA?%in%
for, is this value in a vector of possibilitiessource()
them to clean up the main script.