9 Assignment
9.1 Key Concepts
After reading this chapter you should be able to define the following:
- operators
- objects
- assignment
9.2 Assignment
When we call a function in R, the default behavior of the function is typically to print the results on the screen:
calcMortgage( principal=100000 )
[1] 536.82
If we are creating a script, however, we often need to save the function outputs at each step. We can do this by assigning output to a new variable.
15.year <- calcMortgage( years=15, principal=100000 )
payments.30.year <- calcMortgage( years=30, principal=100000 ) payments.
These values are then stored, and can be used later or printed by typing the object name:
15.year payments.
[1] 790.79
30.year payments.
[1] 536.82
Note that variable names can include periods or underscores. They can also include numbers, but they cannot start with a number. Like everything in R, they will be case sensitive.