surv_group_by: Create a Grouped Dataset for Survival Analysis

Description Usage Arguments Value Examples

View source: R/surv_group_by.R

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

1
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:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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

survminer documentation built on March 9, 2021, 5:07 p.m.