[R] extract from a list of lists

Leonard Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Thu Dec 29 04:20:58 CET 2022


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



More information about the R-help mailing list