sub-.epicontacts: Subset epicontacts objects based on case identifiers

Description Usage Arguments Details Author(s) See Also Examples

Description

The "[" operator can be used to subset epicontacts objects, retaining a specified set of case identifiers (i for the linelist, j for contacts). Note that unlike most classical R objects, there is no replacement method for epicontacts objects, i.e. no operations such as foo[i] <- bar.

Usage

1
2
3
## S3 method for class 'epicontacts'
x[i, j, k = TRUE, l = TRUE, contacts = c("both",
  "either", "from", "to"), ...]

Arguments

x

An epicontacts object

i

A character vector containing case ID to be retained in the linelist; alternatively, an integer or logical vector used to subset the rows of the $linelist component.

j

A character vector containing case ID to be retained in the contacts; alternatively, an integer or logical vector used to subset the rows of the $contacts component.

k

An integer, logical, or character vector subsetting the supplementary columns of x$linelist, i.e. the columns after 'id'; i.e. k=1 refers to the column immediately after 'id'.

l

An integer, logical, or character vector subsetting the supplementary columns of x$contacts, i.e. the columns after 'from' and 'to'; i.e. l=1 refers to the column immediately after 'to'.

contacts

A character string indicating the rules for retaining contacts when j indicates case IDs (see details).

...

Not used (there for compatibility with generic).

Details

Details on the 'contacts' argument; possible values are:

Author(s)

Thibaut Jombart ([email protected])

See Also

thin to retain matching cases in linelist or contacts.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if (require(outbreaks)) {
## build data
x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts,
                       id = "case_id", to = "case_id", from = "infector",
                       directed = TRUE)

## subset first 10 linelist cases
x[1:10]

## same, remove contacts
x[1:10, j = FALSE]

## subset first 10 contacts
x[j = 1:10]

## remove the metadata
x[k = FALSE, j = FALSE]

## keep contacts where both cases are in linelist
x[j = get_id(x, "linelist"), contacts = "both"]

## keep contacts from a specific case '916d0a'
x[j = "916d0a", contacts = "from"]

## more complex: keep all cases and contacts with > 4 secondary contacts
## i) find cases to keep
temp <- table(x$contacts$from)
temp[temp > 4]
to.keep <- names(temp)[temp > 4]
to.keep

## subset the contacts
y <- x[j = to.keep, contacts = "either"]
y

## keep only relevant entries in the linelist
y <- thin(y)

## visualise result
plot(y)
}

epicontacts documentation built on May 2, 2019, 11:29 a.m.