Working with R - Practical

Preface

Open Rstudio to do the practicals. Note that tasks with * are optional.

R packages

In this practical, a number of R packages are used. The packages used (with versions that were used to generate the solutions) are:

  • survival (version: 3.5.7)

R version 4.3.2 (2023-10-31 ucrt)

Dataset

For this practical, we will use the heart and retinopathy data sets from the survival package. More details about the data sets can be found in:

https://stat.ethz.ch/R-manual/R-devel/library/survival/html/heart.html

https://stat.ethz.ch/R-manual/R-devel/library/survival/html/retinopathy.html

Basic calculations

Expressions

Assignment

Now use assignment to do the same calculation. Assign names a, b and c to each of the three values involved, then do the calculation while assigning the name d to the result.

Execute the following code.

a <- 45
b <- 2
c <- 3
d <- (a - b) * c 

a, b, c, and d are variables. To see their values, you can just type the variable name (e.g. a) and hit Ctrl-Enter or use the command print(a).

Importing and Saving Data

Save your work

It is important to save your work.

Load your work

Let’s continue working on the data sets by loading our results.

Remove your work

Remove unnecessary objects.