Open PCK1992 opened 3 months ago
Hi, thank you so much for filing this issue. Here is an example on how to filter alters in an egor object.
library(egor)
# Create example data
e <- egor(
alters = tibble(
egoID = as.numeric(gl(20, 5)),
alterID = rep(1:5, 20),
attribute1 = sample(0:1, 100, replace = TRUE),
attribute2 = sample(0:1, 100, replace = TRUE),
attribute3 = sample(0:1, 100, replace = TRUE)
),
egos = tibble(egoID = 1:20),
aaties = tibble(
egoID = as.numeric(gl(20, 5)),
Source = sample(1:5, 100, replace = TRUE),
Target = sample(1:5, 100, replace = TRUE)
)
)
activate()
the alter dataset and then use dplyr::filter()
to filter the alters data.
e |>
activate(alter) |>
filter(attribute1 == 1)
#> # EGO data: 20 × 1
#> .egoID
#> * <int>
#> 1 1
#> 2 2
#> 3 3
#> # ℹ 17 more rows
#> # ALTER data (active): 55 × 5
#> .altID .egoID attribute1 attribute2 attribute3
#> * <int> <dbl> <int> <int> <int>
#> 1 1 1 1 0 0
#> 2 2 1 1 0 0
#> 3 3 1 1 1 1
#> 4 3 2 1 1 0
#> 5 4 2 1 1 1
#> # ℹ 50 more rows
#> # AATIE data: 35 × 3
#> .egoID .srcID .tgtID
#> * <dbl> <int> <int>
#> 1 1 3 2
#> 2 1 2 2
#> 3 2 4 3
#> # ℹ 32 more rows
To do a filter operation as you describe:
e |>
activate(alter) |>
filter(attribute1 == 1 &
if_all(attribute2:attribute3, \(x) x == 0))
#> # EGO data: 20 × 1
#> .egoID
#> * <int>
#> 1 1
#> 2 2
#> 3 3
#> # ℹ 17 more rows
#> # ALTER data (active): 14 × 5
#> .altID .egoID attribute1 attribute2 attribute3
#> * <int> <dbl> <int> <int> <int>
#> 1 1 1 1 0 0
#> 2 2 1 1 0 0
#> 3 2 3 1 0 0
#> 4 2 4 1 0 0
#> 5 4 6 1 0 0
#> # ℹ 9 more rows
#> # AATIE data: 3 × 3
#> .egoID .srcID .tgtID
#> * <dbl> <int> <int>
#> 1 1 2 2
#> 2 12 1 1
#> 3 14 1 2
Hello,
Perhaps I'm missing something and I checked the documentation but couldn't figure this out yet. Is there any way to remove egos based on some attribute from an egor object after it has been created?
Suppose I create a an egor object using the egor function:
The
ego_nets
object contains information on the alters and I want to remove all alters from the object if they haveattribute1=1
and all other attribute from a set of specified attributes should be zero e.g.attribute2=0
,attribute3=0
, etc.My current code looks like this:
This code keeps crashing on my 32GB laptop.
Is this the way to go to remove unwanted alters for my egor object? Also, is there a more efficient way to do this? There are approximately 2000 ego networks in the data set.
I appreciate any help!