Skip to contents

These work like dplyr's bind_cols() and bind_rows(). The first argument has to be an egor object. Additional rows/columns are added bottom/RHS of the active data level (ego, alter, aatie).

Usage

append_rows(.egor, ..., .id = NULL)

append_cols(.egor, ...)

Arguments

.egor

An egor object.

...

Data frames to combine.

.id

Data frame identifier.

Value

egor object containing the additional rows/ columns on the active level.

Examples

e <- make_egor(12, 15)

# Adding a column to the ego level
additional_ego_columns <-
  tibble(x = sample(1:3, 12, replace = TRUE))
  
append_cols(e, additional_ego_columns)
#> # EGO data (active): 12 × 7
#>   .egoID sex   age      age.years country   income     x
#> *  <dbl> <chr> <fct>        <int> <chr>      <dbl> <int>
#> 1      1 w     26 - 35         32 Australia  35405     1
#> 2      2 w     66 - 100        80 Australia  60955     1
#> 3      3 w     56 - 65         63 Germany     1825     2
#> 4      4 m     66 - 100        95 Australia   7665     3
#> 5      5 w     56 - 65         63 USA        17885     2
#> # ℹ 7 more rows
#> # ALTER data: 103 × 7
#>   .altID .egoID sex   age      age.years country income
#> *  <int>  <dbl> <chr> <fct>        <int> <chr>    <dbl>
#> 1      1      1 w     66 - 100        98 Poland   51830
#> 2      2      1 m     0 - 17          13 Germany  17885
#> 3      3      1 m     66 - 100        96 USA      10220
#> # ℹ 100 more rows
#> # AATIE data: 244 × 4
#>   .egoID .srcID .tgtID weight
#> *  <int>  <int>  <int>  <dbl>
#> 1      8      5     11  0.333
#> 2      4      2      4  1    
#> 3     10      3      7  1    
#> # ℹ 241 more rows

# Adding rows to the ego and alter level
additional_ego_rows <-
  list(
    .egoID = 13,
    sex = "w",
    age = factor("56 - 65"),
    age.years = 60,
    country = "Australia"
  ) %>%
  as_tibble()
  
additional_alter_rows <-
  list(
    .altID = 1:5,
    .egoID = rep(13, 5),
    sex = sample(c("f", "m"), 5, replace = TRUE)
  ) %>%
  as_tibble()
  
append_rows(e, additional_ego_rows) %>%
  activate(alter) %>%
  append_rows(additional_alter_rows)
#> # EGO data: 13 × 6
#>   .egoID sex   age      age.years country   income
#> *  <dbl> <chr> <fct>        <dbl> <chr>      <dbl>
#> 1      1 w     26 - 35         32 Australia  35405
#> 2      2 w     66 - 100        80 Australia  60955
#> 3      3 w     56 - 65         63 Germany     1825
#> # ℹ 10 more rows
#> # ALTER data (active): 108 × 7
#>   .altID .egoID sex   age      age.years country   income
#> *  <int>  <dbl> <chr> <fct>        <int> <chr>      <dbl>
#> 1      1      1 w     66 - 100        98 Poland     51830
#> 2      2      1 m     0 - 17          13 Germany    17885
#> 3      3      1 m     66 - 100        96 USA        10220
#> 4      4      1 m     0 - 17           5 Australia  71540
#> 5      5      1 w     66 - 100        82 Poland      5475
#> # ℹ 103 more rows
#> # AATIE data: 244 × 4
#>   .egoID .srcID .tgtID weight
#> *  <int>  <int>  <int>  <dbl>
#> 1      8      5     11  0.333
#> 2      4      2      4  1    
#> 3     10      3      7  1    
#> # ℹ 241 more rows