3  Practice the basics

Arithmetic and Variables

  1. Add together 100 and 150. Save this as a variable (choose your own name).
  1. Subtract 50 from this variable. Save this as a new variable.
  1. Print the value of the second variable:
  1. In a single cell, multiply the second variable by the first one, and then divide it by 2:
  1. Create a variable, called x, and set it to a numeric value:
  1. Change the value of x to 500
  1. Print the value of x:

Strings

  1. Create a string (choose the name of the object yourself), containing the name of the student nearest to you.
  1. Print this string:
  1. Calculate how many characters are in this string:

Vectors

  1. In one cell, create two vectors: first, a character vector containing the first names of the three students closest to you. Second, a numeric vector containing the years of birth of these three students.

Comparisons

  1. Check if 100 multiplied by 5 is equal to 50 multiplied by 10:
  1. Using the vector of student names you created above, check if any of the elements in the vector are equal to the string "Yann".