Celia Evans
7/27/2021
A function to calculate the \(y\) value for a given \(x\) value. Where y is given by numbers \(m\) and \(b\) according to the formula:
\[y = mx + b\]
Using the function:
## [1] 5
Equivalently:
## [1] 5
Suppose you have a large number of \(x\) values, say 100, and you want to evaluate the preceding function at each of them.
Let’s make a plot to see what we’ve done.
A function has only two parts:
A function takes a set of arguments and processes them by the code in the body.
Notice that nothing is said about a function name. Why not?
## [1] 58
You don’t really need it!
R is a functional language, that means, among other things, that functions can be passed and returned by other functions.
(Sometimes people say that functions are first class objects.) When might this be useful?
Another consequence is that it is easy to make aliases for functions.
## [1] TRUE
Whenever you have to use the same code in different places in your program.
Example: Recall last weeks lab. We had to convert time stored in HHMM or HMM format into minutes.
## [1] 615
Write a function to evaluate the linear combination of a set of numbers. For example, given coefficeints a, b, c and numbers x y z calculate ax + by + cz. Try to write the most useful version of the function that you can.