I'd like to find a clean and readable way to convert a structure like src
(parsed from JSON, that's why there are a ton of nested lists) to one like dst
.
src <- list(
sessions=list(
list(
statistics=list(
list(
list(
round=0,
diff=3,
saldo=3
),
list(
round=1,
diff=-1,
saldo=2
),
list(
round=2,
diff=-1,
saldo=1
)
),
list(
list(
round=0,
diff=-1,
saldo=-1
)
)
),
sessionProp="sv1"
),
list(
statistics=list(
list(
list(
round=0,
diff=4,
saldo=4
)
),
list(
list(
round=0,
diff=2,
saldo=2
)
)
),
sessionProp="sv2"
)
),
packageProps=list(
rules=list(
list(
name="Ruleset 1",
ruleProp="rv1"
),
list(
name="Ruleset 2",
ruleProp="rv2"
)
),
packageProp="package prop value"
)
)
dst <- data.frame(
round=c(0,1,2,0,0,0),
diff=c(3,-1,-1,-1,4,2),
saldo=c(3,2,1,-1,4,2),
sessionProp=c("sv1","sv1","sv1","sv1","sv2","sv2"),
ruleProp=c("rv1","rv1","rv1","rv2","rv1","rv2")
)
Both sessions have two elements in statistics
list. Those correspond to two elements in rules
list packageProps
. That's the only difference from pretty much direct denormalization.