9  Assignment

9.1 Key Concepts

After reading this chapter you should be able to define the following:

  • operators
  • objects
  • assignment



Assignment of output values

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.

payments.15.year <- calcMortgage( years=15, principal=100000  )
payments.30.year <- calcMortgage( years=30, principal=100000  )

These values are then stored, and can be used later or printed by typing the object name:

payments.15.year
[1] 790.79
payments.30.year
[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.