Re: [R] converting a list to a data.frame

From: Mark Wardle <>
Date: Tue 03 Apr 2007 - 11:35:21 GMT

Biscarini, Filippo wrote:
> Dear Mark,
> If you have time you can try directly into R this excerpt from my list.

This is horrible code, and I should be shot! I would appreciate any better ways of doing this, but I think this works!

l = list(c(1,2,4),c(4,5,2,1),c(3,4,6,3),c(3,1,76,4,2)) <- function(list) {

        max.length = 0
        x = NULL
		for(i in list) max.length = max(max.length, length(i))
		for(i in list) {
        	d = c(i, rep(NA, max.length - length(i)))
        	if(is.null(x)) x = rbind(unlist(d))
        	else x = rbind(x, unlist(d))


It works on the data you sent me:


Have fun,


Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue Apr 03 21:40:48 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 03 Apr 2007 - 12:30:48 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.