update_from_table: Update a named vector with values from a table

View source: R/sbtab_utilities.R

update_from_tableR Documentation

Update a named vector with values from a table

Description

This function can be used in the circumstance that you already have a default vector and want to update some of its entries from a data.frame with more specific values. The table describes the circumstamces of these more specific values and has columns named like the vector elements. The function returns a matrix with one column per scenario, updated using the table. This is used while parsing SBtab tables.

Usage

update_from_table(v, Table, prefix = ">", v.strip = "_ConservedConst$")

Arguments

v

the vector to update

Table

a table with column names partially matching those in v

prefix

in the Table, the columns are named "paste(suffix,names(v))"

Details

The returned value M has several copies of vector v with some values changed accoring to a table (Qantity Matrix) If the table has columns that name members of v (also named) they will be used. The M will have as many columns as the table has rows.

When the columns in the Table have a prefix, this can be compensated: say, the names(v) are c("a", "b", "c") but in the Table we have names(Table) as c(">a",">b",">abc",">d") then setting prefix to ">" will match a and b correctly and none of the others.

Whenever one of the items in v has a name ending in _ConservedConst it is assumed to be the result of conservation law analysis and matching is done disregarding the _ConservedConst suffix.

Value

a matrix with various versions of v (columns) one per setting described in data.frame Table. The names can have a ">" prefix in the names (see SBtab rules)

Examples

> v<-c(1,2,3)
> names(v)<-c('a','b','c')

> data<-data.frame(row.names=c('low','med','high'),
  b=c(0.5,2.5,5.5),
  comment=c('b < 1','close to default','b > 2×default'))

       b   comment
low  0.5   b < 1
med  2.5   close to default
high 5.5   b > 2×default

> update_from_table(v,data,prefix="")
  low med high
a 1.0 1.0  1.0
b 0.5 2.5  5.5
c 3.0 3.0  3.0

a-kramer/SBtabVFGEN documentation built on Dec. 15, 2024, 1:52 a.m.