Learn R Programming

hesim (version 0.2.0)

expand.hesim_data: Expand hesim_data

Description

Expand the data tables from an object of class hesim_data into a data table in long format (one row for each combination of observations as specified with the ID variables from the tables specified with the by argument). See "Details" for an explanation of how the expansion is done.

Usage

# S3 method for hesim_data
expand(object, by = c("strategies", "patients"))

Arguments

object

An object of class hesim_data.

by

A character vector of the names of the data tables in hesim_data to expand by.

Value

An object of class "expanded_hesim_data", which is a data.table with an "id_vars" attribute containing the names of the ID variables in the data table.

Details

This function is similar to expand.grid, but works for data frames or data tables. Specifically, it creates a data.table from all combinations of the supplied tables in object. The supplied tables are determined using the by argument. The resulting dataset is sorted by prioritizing ID variables as follows: (i) strategy_id, (ii) line, (iii) patient_id, (iv) the health-related ID variable (either state_id or transition_id), and (v) the time interval (i.e., time_id).

Examples

Run this code
# NOT RUN {
strategies <- data.frame(strategy_id = c(1, 2))
patients <- data.frame(patient_id = seq(1, 3), age = c(65, 50, 75),
                          gender = c("Female", "Female", "Male"))
states <- data.frame(state_id =  seq(1, 3),
                     state_var = c(2, 1, 9))
hesim_dat <- hesim_data(strategies = strategies,
                        patients = patients,
                        states = states)
expand(hesim_dat, by = c("strategies", "patients"))
# }

Run the code above in your browser using DataLab