Activity
Open up a new script, use all the proper headings and working directory settings, and do the following:
Create a for loop that takes a vector of numbers
vec <- c(1,2,3,4,5)
and adds each number to the previous numbers to produce the output 1, 3, 6, 10, 15. This output may either be printed usingprint()
or stored as a new vector.given the vector
x <- c("Monday", "Sunday", "Wednesday", "Friday", "Thursday)
, use aifelse()
statement to categorize the days in x as either “weekend” or “weekday”.
-
Turn each of the following code blocks into functions.Think about what each function does. Follow the specific guidelines in the lab manual to properly document, name, and assign arguments to the functions.
function 1:
function 2:
function 3:
Create a function
celsius_to_fahrenheit
in R that takes a numeric or vector of temperatures in Celsius, and returns its equivalent in Fahrenheit. Follow the specific guidelines in the lab manual to properly document, name, and assign arguments to the functions (this is very important).
here is the mathematical formula for the conversion:
\[ \text{Fahrenheit} = \left( \frac{9}{5} \times \text{Celsius} \right) + 32 \]