I have list where the elementnames are ID-tags and contains a vector with numeric values. These are of unequal(!) length.
I want to transform it to a data frame where I have the ID in one column and the numeric values in another column. E.g.:
$`1`
[1] 1 2
$`2`
[1] 1 2 3
$`3`
[1] 1
To:
ID Obs
1 1
1 2
2 1
2 2
2 3
3 1
Here is one way:
This gives:
The first line in the
data.frame()call is just some code to repeat thenames()of the list the required number of times. The second line just unlists the list converting it into a vector.