I have a list of lists. I want to order this according to a reference vector. This is similar to this question on ordering dataframes. However I struggled to implement it.
I want to sort this list below by its 'key' according to the order in the 'target' vector.
target <- c("c", "b", "a")
L <- list(
X = list(key = "a", val = 6),
Y = list(key = "b", val = 5),
Y = list(key = "b", val = 0),
Z = list(key = "c", val = 4)
)