I'm reading a yaml file like
- person_id: 111
person_name: Russell
time:
- 1
- 2
- 3
value:
- a
- b
- c
- person_id: 222
person_name: Steven
time:
- 1
- 2
value:
- d
- e
that I want to denormalize to:
person_id person_name time value
1 111 Russell 1 a
2 111 Russell 2 b
3 111 Russell 3 c
4 222 Steven 1 d
5 222 Steven 2 e
I have a solution, but I was hoping there is something more concise. Here's the nested list:
l <- list(
list(
person_id = 111L,
person_name = "Russell",
time = 1:3,
value = letters[1:3]
),
list(
person_id = 222L,
person_name = "Steven",
time = 1:2,
value = letters[4:5]
)
)
Regarding possible duplicates, this question is similar to (1) How to denormalize nested list in R?, but the structure is different (the round
/diff
/saldo
structure is transposed compared to time
/value
here), and to (2) Split comma-separated column into separate rows, but time
is vector, instead of a comma-separated element like director
. I'm hoping this different structure helps.