4.2 Storing Information
We can extend the calculator function to create variables to store the information. We can do the following:
<- 4
x <- 9
y <- sqrt(x + y) z
With the above R code, you would assign (using the <- operator) \(x\) to have the value of 4; \(y\) to have the value of 9; and \(z\) to have the result of the square root of the sum of \(x + y\).
Hint: you can use a keyboard shortcut to obtain the <- symbol. For PC users, click the Alt key along with - key while for those using a MAC, click the option key along with the - key.
Once you execute the code (i.e. run the code), nothing seems to have happened, other than R showing the ready prompt. (Note: you can use an equal sign (=). There are differences of opinions as to which to use.)
That is nice, but how do you know the result of the calculation? If you type \(x\) in the console at the ready prompt, you see it is assigned the value of 4. Similarly if you type \(z\) in the console at the ready prompt, you see the result of that calculation.
x
y z