Preface

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:

  • R version 4.0.3 (2020-10-10)
  • survival (version: 3.2.7)

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

Importing and Saving Data

Save your work

It is important to save your work.

Task 1

Save the vectors numbers <- c(34, 24, 19, 23, 16), numbers_2 <- c(1:200) and treatment <- c("yes", "yes", "no", "no", "no", "yes"). Use the name new_vectors.

Use the function save(…). Note that you need to set the working directory.

Solution 1

numbers <- c(34, 24, 19, 23, 16)
numbers_2 <- c(1:200)
treatment <- c("yes", "yes", "no", "no", "no", "yes")
save(numbers, numbers_2, treatment, file = "new_vectors.RData")

Task 2

Save the vectors events <- heart$event and eyes <- retinopathy$eye. Use the name vectors_survival.

Use the function save(...). Note that you need to set the working directory.

Solution 2

events <- heart$event
eyes <- retinopathy$eye
save(events, eyes, file = "vectors_survival.RData")

Load your work

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

Task

Load the file new_vectors.

Use the function load(…).

Solution

load("new_vectors.RData")

Remove your work

Remove unnecessary objects.

Task 1

Remove the vectors numbers, numbers_2 and treatment.

Use the function rm(…).

Solution 1

rm(numbers, numbers_2, treatment)

Task 2

Remove the vectors events and eyes.

Use the function rm(…).

Solution 2

rm(events, eyes)
 

© Eleni-Rosalina Andrinopoulou