2 + 2[1] 4
By the end of this lesson, you will be able to:
All examples use base R; no additional R packages are required to run them.
Type the following expression into the RStudio Console and press Enter:
The output is 4. R uses * for multiplication and / for division.
Use <- to assign a value to a variable. You can then use its name in later calculations.
This calculation returns 25. The stored value remains 20 because we did not assign a new value to number_of_students.
The function c() combines values into a vector. Here we use invented practice scores.
The mean is 10: the sum of the five scores is 50, and 50 / 5 = 10.
Create a vector containing 5, 10, and 15, then calculate its mean.