Annotates id-time points table by the values given in the second table.

emr_annotate(x, y)

Arguments

x

sorted id-time points table that is expanded

y

sorted id-time points table that is used for annotations

Value

A data frame with all the columns from 'x' and additional columns from 'y'.

Details

This function merges two sorted id-time points tables 'x' and 'y' by matching 'id', 'time' and 'ref' columns. The result is a new id-time points table that has all the additional columns of 'x' and 'y'.

Two rows match if 'id' AND 'time' match AND either 'ref' matches OR one of the 'ref' is '-1'.

If a row RX from 'x' matches N rows RY1, ..., RYn from 'y', N rows are added to the result: [RX RY1], ..., [RX RYn].

If a row RX from 'x' does not match any rows from 'y', a row of [RX NA] form is added to the result (i.e. all the values of columns borrowed from 'y' are set to 'NA').

A missing 'ref' column is interpreted as if reference equals '-1'.

Both of 'x' and 'y' must be sorted by 'id', 'time' and 'ref' (in this order!). Note however that all the package functions (such as 'emr_extract', ...) return id-time point tables always properly sorted.

See also

Examples


emr_db.init_examples()
#> NULL

r1 <- emr_extract("sparse_track", keepref = TRUE)
r2 <- emr_extract("dense_track", keepref = TRUE)
r2$dense_track <- r2$dense_track + 1000
emr_annotate(r1, r2)
#>    id time ref sparse_track dense_track
#> 1   5    1   3           13          NA
#> 2  10    1   3           13          NA
#> 3  25    1   0           10        1010
#> 4  25    2   0           20        1020
#> 5  25    2   2           22        1022
#> 6  25    2   4           24          NA
#> 7  25    2   6           26        1026
#> 8  25    2   8           28        1028
#> 9  25    3   4           34        1034
#> 10 25    6   0           60        1060
#> 11 25    6   2           62        1062
#> 12 25    8   1           80        1080
#> 13 25    8   4           84        1084
#> 14 25    9   2           92        1092
#> 15 25    9   4           94        1094
#> 16 25   10   4          104        1104
#> 17 25   12   4          124        1124
#> 18 27   23   4          234        1234
#> 19 33   23   4          234          NA
#> 20 33   50   0          500          NA
#> 21 40    1   3           13          NA