Basic solution
List <- list('1'=c(1,2), '2'= c(1,2,3), '3'=1) x <- unlist(List)
If you want rownames be 1,2,3,4,5,6 try this (using setNames ):
data.frame(ID=substr(names(x),1,1), Obs=setNames(x, NULL)) ID Obs 1 1 1 2 1 2 3 2 1 4 2 2 5 2 3 6 3 1
This solution only works if all the names are the same length, otherwise it will fail, and it would be better to use the Gavin solution. See for example:
List2 <- list('week1'=c(1,2), 'week2'= c(1,2,3), 'week3'=1) x <- unlist(List2) data.frame(ID=substr(names(x),1,nchar(names(x)[1])-1), Obs=setNames(x, NULL)) ID Obs 1 week1 1 2 week1 2 3 week2 1 4 week2 2 5 week2 3 6 week3 1
source share