I have a list of lists like ll:
ll <- list(a = list(data.frame(c = 1, d = 2), data.frame(h = 3, j = 4)), b = list(data.frame(c = 5, d = 6), data.frame(h = 7, j = 9)))
I want to add one variable grp to each final list. This variable (grp) has to contain the name/value of each list. Therefore the new list of lists may look like ls:
ls <- list(a = list(data.frame(c = 1, d = 2, grp = 1), data.frame(h = 3, j = 4, grp = 2)), b = list(data.frame(c = 5, d = 6, grp = 1), data.frame(h = 7, j = 9, grp = 2)))
NOTE: The grp may not follow a sequence from 1:n. The approach I look for may be similar to the following one bind_rows(df, .id = 'grp')
. The only point is that in this case, I don´t want to row bind (at least not in this way but in this other Unlist LAST level of a list in R)
Any clue?