Description Usage Arguments Value Examples
Using a matrix of IDs, look up a value in a dataframe
1 | return_value_from_id(ids, df, value)
|
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 |
Matrix of values corresponding to the input ID matrix
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.