I have a data frame like this
id key value
1 x a 1
2 x b 2
3 y a 3
4 y b 4
read.table(text = "id key value
x a 1
x b 2
y a 3
y b 4", header = TRUE, sep = "\t")
And I would like to get a list for each id
with sub lists for each key
So with my example the expected output would be :
$x
$x$a
$x$a$value
[1] 1
$x$b
$x$b$value
[1] 2
$y
$y$a
$y$a$value
[1] 3
$y$b
$y$b$value
[1] 4
list(
x = list(
a = list(value = 1),
b = list(value = 2)
),
y = list(
a = list(value = 3),
b = list(value = 4)
)
)
I can achieve it with nested lapply
and split
but I think there should be a more straightforward way to do it.
Any help would be appreciated.