View source: R/surv_group_by.R
surv_group_by | R Documentation |
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".
surv_group_by(data, grouping.vars)
data |
a data frame |
grouping.vars |
a character vector containing the name of grouping variables. Should be of length <= 2 |
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.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.