Learn R Programming

survminer (version 0.4.7)

surv_group_by: Create a Grouped Dataset for Survival Analysis

Description

Split a data frame into multiple new data frames based on one or two grouping variables. The surv_group_by() function takes an existing data frame and converts it into a grouped data frame where survival analysis are performed "by group".

Usage

surv_group_by(data, grouping.vars)

Arguments

data

a data frame

grouping.vars

a character vector containing the name of grouping variables. Should be of length <= 2

Value

Returns an object of class surv_group_by which is a tibble data frame with the following components:

  • one column for each grouping variables. Contains the levels.

  • a coumn named "data", which is a named list of data subsets created by the grouping variables. The list names are created by concatening the levels of grouping variables.

Examples

Run this code
# NOT RUN {
library("survival")
library("magrittr")

# Grouping by one variables: treatment "rx"
#::::::::::::::::::::::::::::::::::::::::::
grouped.d <- colon %>%
  surv_group_by("rx")

grouped.d # print

grouped.d$data # Access to the data

# Grouping by two variables
#::::::::::::::::::::::::::::::::::::::::::
grouped.d <- colon %>%
   surv_group_by(grouping.vars = c("rx", "adhere"))
   grouped.d

# }

Run the code above in your browser using DataLab