Skip to content

extract from a list of lists

1 message · Leonard Mada

#
Dear Terry,

The following approach may be more suitable:

fits <- lapply(argument, function)
fits.df = do.call(rbind, fits);

It works if all the lists returned by "function" have the same number of elements.

Example:
fits.df = lapply(seq(3), function(id) {
	list(
	beta = rnorm(1), loglik = id^2,
	iter = sample(seq(100,200), 1), id = id);
})
fits.df = do.call(rbind, x);
fits.df

I have added an id in case the function returns a variable number of "rows".

Sincerely,

Leonard