Primary exercises

  1. Create a new variable.
    Make a variable heightInMeters that contains your height expressed in meters.
    Print the variable.
    Find the variable and its value in the Environment pane.

  2. Use a variable in an expression.
    Use the variable heightInMeters to calculate your height in cm.
    Calculate the height in cm once again and store the result in a variable heightInCentimeters.
    Show/print heightInCentimeters.

  3. Change a value of a variable.
    Increase the height stored in heightInMeters by 0.1m.
    Check whether the value of the variable indeed changed.
    Has the value of heightInCentimeters also changed? Why?

  4. Typo in variable name.
    Observe the error shown when you try to print a variable but you make a typo in the variable name.

Extra exercises

  1. The pi.
    pi is a variable built in R. Use it to calculate the area of a circle of radius 2.0.

  2. Various assignment operators.
    In addition to <- R has other assignment operators = (equivalent to <-) and -> (the variable name on the right side).
    Use each of these operators in an assignment. When do you think -> might be useful?

  3. List defined variables; remove a variable.
    Use ls() to find what variables are currently known. Compare the output with the content of the Environment pane.
    Define a new variable xyz = 5. Find how to use rm to remove the variable from the current environment.

  4. Restart R session.
    (Warning: you are going to loose all what you have typed).
    First define several variables (so you can see some in the Envinroment pane).
    Try Restart R option from the Session menu.
    What happened? What happened to the variables?



Copyright © 2023 Biomedical Data Sciences (BDS) | LUMC