[R] Convert list of lists <--> data frame

2008-07-23 Thread Michael Friendly
For a function that takes an argument as a list of lists of parameters, I'd like to be able to convert that to a data.frame and vice versa, but can't quite figure out how. pats <- list(structure(list(shape = 0, shape.col = "black", shape.lty = 1, cell.fill = "white", back.fill = "white", labe

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread N. Lapidus
Not very elegant but seems to work: pats.df <- as.data.frame(t(sapply (1:length(pats), function (i) do.call(cbind,pats[[i]] colnames(pats.df) <- names(pats[[1]]) # then pats2 <- lapply (1:nrow(pats.df), function (i) as.list(t(pats.df)[,i])) Nael On Wed, Jul 23, 2008 at 3:23 PM, Michael Frie

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Henrique Dallazuanna
Try this: pats.df <- do.call(rbind, pats) On Wed, Jul 23, 2008 at 10:23 AM, Michael Friendly <[EMAIL PROTECTED]> wrote: > For a function that takes an argument as a list of lists of parameters, I'd > like to be able to convert that > to a data.frame and vice versa, but can't quite figure out how.

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Marc Schwartz
on 07/23/2008 08:23 AM Michael Friendly wrote: For a function that takes an argument as a list of lists of parameters, I'd like to be able to convert that to a data.frame and vice versa, but can't quite figure out how. pats <- list(structure(list(shape = 0, shape.col = "black", shape.lty = 1,

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Patrizio Frederic
try ?unlist it may help regards +- | Patrizio Frederic | Research associate in Statistics, | Department of Economics, | University of Modena and Reggio Emilia, | Via Berengario 51, | 41100 Modena, Italy | | tel: +39 059 205 6727 | fax: +39 059 2

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Ben Bolker
Michael Friendly yorku.ca> writes: > > For a function that takes an argument as a list of lists of parameters, > I'd like to be able to convert that > to a data.frame and vice versa, but can't quite figure out how. > [snip data] pats.df <- do.call("rbind",pats) pats2 <- apply(pats.df,1,

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Jorge Ivan Velez
Dear Michael, Perhaps, data.frame(do.call(rbind,lapply(pats,function(x) t(as.matrix(x,ncol=10) HTH, Jorge On Wed, Jul 23, 2008 at 9:23 AM, Michael Friendly <[EMAIL PROTECTED]> wrote: > For a function that takes an argument as a list of lists of parameters, I'd > like to be able to conv

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Marc Schwartz
on 07/23/2008 09:42 AM Henrique Dallazuanna wrote: Try this: pats.df <- do.call(rbind, pats) Henrique, Take note of the object that results from this: > do.call(rbind, pats) shape shape.col shape.lty cell.fill back.fill label label.size [1,] 0 "black" 1 "white" "white"

Re: [R] Convert list of lists <--> data frame

2008-07-23 Thread Henrique Dallazuanna
Oh, you are rigth Marc, thanks. Another option is: pats.df <- do.call(rbind.data.frame, pats) On Wed, Jul 23, 2008 at 1:10 PM, Marc Schwartz <[EMAIL PROTECTED]> wrote: > on 07/23/2008 09:42 AM Henrique Dallazuanna wrote: >> >> Try this: >> >> pats.df <- do.call(rbind, pats) > > Henrique, > > Tak