I’m trying to prepare a data structure which I will need at later point in my script. Let’s say I’m in a graph domain and my nodes (sometimes only 1, but mostly 2 or even 3) have names (e.g., "left", "right", "center"). The names are stored in a variable:
origin_target_list <- c("left", "center", "right", "")
Given the list with the three items from above, I’m trying to create this data structure dynamically:
origin_target_combinations <- list(
left = list( # origin is left
right = c(), # target is right
center = c(), # target is center
unknown = c() # target is somewhere else / unknown
),
right = list(
left = c(),
center = c(),
unknown = c()
),
center = list(
left = c(),
right = c(),
unknown = c()
),
unknown = list( # origin is unknown
left = c(), # target is left
center = c(), # target is center
right = c() # target is right
)
)
EDIT: The constrain is origin and target cannot be the same. Thus, every element in the origin_target_list plus "unknown" should be combined.
Similar, a list with one element: origin_target_list <- c("center") would only create the unknown case:
origin_target_combinations <- list(
unknown = list(
left = c(),
center = c(),
right = c()
)
)
I know this is a complex problem, I working on a solution myself right now... I'll keep this post updated with my attempts...