R Basics
Interactive beginner R tutorial: use R as a calculator, store values in variables, call functions and write comments β running real R in your browser.
Welcome to R. Everything below is a live R console β edit the code and press Run Code. Nothing to install.
R is a calculator
Run this, then change the numbers and run it again:
R evaluates each line and prints the result. ^ is βto the power ofβ.
Store values in variables
Use <- (type it as < then -) to save a value under a name:
Now price and quantity hold values you can reuse. Try adding a discount variable and subtracting it.
Call functions
A function does something to its input, written as name(input):
round(x, 2) rounds to 2 decimals β the parts inside the brackets are called arguments.
Your turn
Change the radius above, or compute something new here:
Next: Vectors β β how R stores and works with many values at once.
Comments
Anything after
#is a comment β R ignores it. Use comments to explain your code: