Loading and observing data
In this recipe, we will see how to load and view survival data. We will create a response object to fit in the survival model.
Getting ready
This recipe requires survival package, as we will be using a dataset from it.
How to do it...
Perform the following steps to perform survival analysis:
- You should install the
survival
package and load its library:
> install.packages("survival")> library(survival)
- From the package, you can load the
cancer
dataset:
> data(cancer)
- You can use the
str
function to display the structure of thecancer
dataset:
> str(cancer) Output 'data.frame': 228 obs. of 10 variables: $ inst : num 3 3 3 5 1 12 7 11 1 7 ... $ time : num 306 455 1010 210 883 ... $ status : num 2 2 1 2 2 1 2 2 2 2 ... $ age : num 74 68 56 57 60 74 68 71 53 61 ... $ sex : num 1 1 1 1 1 1 2 2 1 1 ... $ ph.ecog : num 1 0 0 1 0 1 2 2 1 2 ... ...