Expand a table based on possibly overlapping group membership.
weave_to_tbl.RdExpand a table into a tidy table suitable for tidyverse-stype operations.
Arguments
- x
a
MultiFactor.- .path
either a
formulaor a `character vector“ of length 2 with the names of the desired combination of feature types.- .data
A table. Adata.frame,matrix, other object with rows and columns. Should have acbindmethod.- .index
Character scalarColumn to look for feature IDs to link. Default: "row.names".
Examples
# Prepare data
x <- trade_posts()
# Generate small example feature table 'df'.
n <- nlevels(x)[["clothing"]]
df <- replicate(10, rbinom(n, rbinom(n, 100, runif(n)), runif(n)))
#' # Ensure rownames correspond to the second (RHS) variable in the formula.
df <- as.data.frame(df, row.names = levels(x)$clothing)
# Apply arbitrary code to x based on group membership
weave_to_tbl(x, .path = fruit ~ clothing, .data = df)
#> fruit clothing V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
#> 1 grapes t-shirt 10 29 5 4 52 72 30 6 53 44
#> 2 pears dress 14 5 31 19 3 65 2 43 11 16
#> 3 apples socks 21 14 15 48 25 16 10 25 40 14
#> 4 grapes socks 21 14 15 48 25 16 10 25 40 14
#> 5 cherries gloves 2 13 8 4 2 21 13 45 5 38
#> 6 melons gloves 2 13 8 4 2 21 13 45 5 38
#> 7 grapes gloves 2 13 8 4 2 21 13 45 5 38
#> 8 pears scarf 4 18 43 12 56 36 1 2 24 28
#> 9 cherries scarf 4 18 43 12 56 36 1 2 24 28