Give it a try. The new lengths() function comes in handy here.
data.frame(name = rep(name, lengths(num)), num = unlist(num))
To understand this a little better, let me break it into pieces from the inside. lengths() indicates the lengths of each item in the list, so we have
lengths(num)
Now we use this as the times argument to rep() to replicate name elements.
rep(name, lengths(num)) # [1] "Alex" "Alex" "Alex" "Patrick" "Patrick" "Patrick" "Patrick"
So, to the first column. For the second column, we just turn num into an atomic vector with unlist() .
unlist(num)
Put them together as shown above, and we have a new data frame.
source share