return_value_from_id: Look up the value that corresponds to a numeric ID

Description Usage Arguments Value Examples

View source: R/treatment.R View source: R/screentreat_library.R View source: R/general.R

Description

Using a matrix of IDs, look up a value in a dataframe

Usage

1
return_value_from_id(ids, df, value)

Arguments

ids

Matrix of ids

df

Data frame containing the values of interest, sorted by ID (i.e., row numbers should correspond to the ID numbers)

value

Column name of value to return from the df

Value

Matrix of values corresponding to the input ID matrix

Examples

1
2
3
4
5
6
7
8
# Simple age distribution
ages <- data.frame(age=c(20,30,40), prop=c(0.2, 0.5, 0.3))
# Simulate a population of size 10 twice, using these proportions and the row IDs
sims <- sim_multinom(nsims=100, 2, ages$prop, names=1:nrow(ages))
# Get the corresponding ages
sim.ages <- return_value_from_id(sims, df=ages, value='age')
# Proportions match input props
round(prop.table(table(sim.ages)), 2)

cancerpolicy/bcimodel documentation built on June 15, 2018, 12:31 a.m.