Functions to index and take subsets of egor() objects: manipulate egos, alters, or alter-alter ties.

# S3 method for egor
subset(x, subset, ..., unit = attr(x, "active"))

# S3 method for egor
[(x, i, j, unit = attr(x, "active"), ...)

Arguments

x

an egor() object.

subset

either an expression evaluated on each of the rows of the selected unit (as in the eponymous argument of subset()) or a function whose first argument is a row, specifying which egos, alters, or alter-alter ties to keep. The expressions can access variables in the calling environment; columns of the active unit, columns of other units with which the active unit shares an ego via egos$, alters$, and aaties$ as well as the following "virtual" columns to simplify indexing:

Ego index .egoRow

contains the index (counting from 1) of the row being evaluated. (This can be used to access vector variables in the calling environment.)

Alter index .altRow

contains the index (counting from 1) of the row number in the alter table.

Alter--alter indices .srcRow and .tgtRow

contain the index (counting from 1) of the row of the alter being refereced by .srcID and .tgtID. (This can be used to quickly access the attributes of the alters in question.)

...

extra arguments to subset if subset is a function; otherwise unused.

unit

a selector of the unit of analysis being affected: the egos, the alters or the (alter-alter) ties. Note that only one type of unit can be affected at a time. Defaults to the current active unit selected by activate.egor().

i

numeric or logical vector indexing the appropriate unit.

j

either an integer vector specifying which columns of the filtered structure (ego, alters, or ties) to select, or a logical vector specifying which columns to keep. Note that the special columns .egoID, .altID, .srcID, .tgtID are not indexed by j.

Value

An egor() object.

Details

Removing or duplicating an ego will also remove or duplicate their alters and ties.

Examples

# Generate a small sample dataset (e <- make_egor(5,4))
#> # EGO data (active): 5 x 6 #> .egoID sex age age.years country income #> <dbl> <chr> <fct> <int> <chr> <dbl> #> 1 1 m 66 - 100 82 Poland 45990 #> 2 2 w 18 - 25 24 Australia 11680 #> 3 3 m 66 - 100 83 Poland 36135 #> # ALTER data: 16 x 7 #> .altID .egoID sex age age.years country income #> <int> <dbl> <chr> <fct> <int> <chr> <dbl> #> 1 1 1 w 66 - 100 83 USA 59495 #> 2 2 1 m 66 - 100 73 USA 5475 #> 3 1 2 m 36 - 45 44 Australia 12775 #> # AATIE data: 10 x 4 #> .egoID .srcID .tgtID weight #> <int> <int> <int> <dbl> #> 1 2 1 4 0.333 #> 2 3 1 2 0.667 #> 3 2 3 4 0.333
# First three egos in the dataset e[1:3,]
#> # EGO data (active): 3 x 6 #> .egoID sex age age.years country income #> <dbl> <chr> <fct> <int> <chr> <dbl> #> 1 1 m 66 - 100 82 Poland 45990 #> 2 2 w 18 - 25 24 Australia 11680 #> 3 3 m 66 - 100 83 Poland 36135 #> # ALTER data: 10 x 7 #> .altID .egoID sex age age.years country income #> <int> <dbl> <chr> <fct> <int> <chr> <dbl> #> 1 1 1 w 66 - 100 83 USA 59495 #> 2 2 1 m 66 - 100 73 USA 5475 #> 3 1 2 m 36 - 45 44 Australia 12775 #> # AATIE data: 6 x 4 #> .egoID .srcID .tgtID weight #> <int> <int> <int> <dbl> #> 1 2 1 4 0.333 #> 2 3 1 2 0.667 #> 3 2 3 4 0.333
# Using an external vector # (though normally, we would use e[.keep,] here) .keep <- rep(c(TRUE, FALSE), length.out=nrow(e$ego)) subset(e, .keep)
#> # EGO data (active): 3 x 6 #> .egoID sex age age.years country income #> <dbl> <chr> <fct> <int> <chr> <dbl> #> 1 1 m 66 - 100 82 Poland 45990 #> 2 3 m 66 - 100 83 Poland 36135 #> 3 5 m 56 - 65 60 Australia 32120 #> # ALTER data: 8 x 7 #> .altID .egoID sex age age.years country income #> <int> <dbl> <chr> <fct> <int> <chr> <dbl> #> 1 1 1 w 66 - 100 83 USA 59495 #> 2 2 1 m 66 - 100 73 USA 5475 #> 3 1 3 m 0 - 17 16 Australia 45625 #> # AATIE data: 2 x 4 #> .egoID .srcID .tgtID weight #> <int> <int> <int> <dbl> #> 1 3 1 2 0.667 #> 2 3 2 4 0.333