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

Description Usage Arguments Value Examples

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 30, 2019, 12:39 a.m.