Subset a btdata object by selecting components from it.
select_components(btdata, subset, return_graph = FALSE)
btdata | An object of class "btdata", typically the result ob of ob <- btdata(..). See |
---|---|
subset | A condition for selecting a subset of the components. This can either be a character vector of names of the components, a single predicate function (that takes a component as its argument), or a logical vector of the same length as the number of components). |
return_graph | Logical. If TRUE, an igraph object representing the comparison graph of the selected components will be returned. |
A btdata
object, which is a list containing:
A square matrix, where the \(i,j\)-th element is the number of times item \(i\) has beaten item \(j\).
A list of the fully-connected components. The names of the list preserve the names of the original btdata
object.
The comparison graph of the selected components (if return_graph = TRUE).
toy_df_4col <- codes_to_counts(BradleyTerryScalable::toy_data, c("W1", "W2", "D")) toy_btdata <- btdata(toy_df_4col) ## The following all return the same component select_components(toy_btdata, "3", return_graph = TRUE)#> Warning: There needs to be a graph component in btdata to return a graph here#> $wins #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Amy Ben Cyd Dan #> Amy . 0.5 . 2 #> Ben 0.5 . . 1 #> Cyd 2.0 . . . #> Dan . 1.0 1 . #> #> $components #> $components$`3` #> [1] "Amy" "Ben" "Cyd" "Dan" #> #> #> attr(,"class") #> [1] "btdata" "list"select_components(toy_btdata, function(x) length(x) == 4)#> $wins #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Amy Ben Cyd Dan #> Amy . 0.5 . 2 #> Ben 0.5 . . 1 #> Cyd 2.0 . . . #> Dan . 1.0 1 . #> #> $components #> $components$`3` #> [1] "Amy" "Ben" "Cyd" "Dan" #> #> #> attr(,"class") #> [1] "btdata" "list"select_components(toy_btdata, function(x) "Cyd" %in% x)#> $wins #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Amy Ben Cyd Dan #> Amy . 0.5 . 2 #> Ben 0.5 . . 1 #> Cyd 2.0 . . . #> Dan . 1.0 1 . #> #> $components #> $components$`3` #> [1] "Amy" "Ben" "Cyd" "Dan" #> #> #> attr(,"class") #> [1] "btdata" "list"select_components(toy_btdata, c(FALSE, FALSE, TRUE))#> $wins #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Amy Ben Cyd Dan #> Amy . 0.5 . 2 #> Ben 0.5 . . 1 #> Cyd 2.0 . . . #> Dan . 1.0 1 . #> #> $components #> $components$`3` #> [1] "Amy" "Ben" "Cyd" "Dan" #> #> #> attr(,"class") #> [1] "btdata" "list"