Will using the function mlply() rather than maply() do the trick for you? For example dat <- data.frame(dim1=1:10, dim2=1:10) foo <- maply(dat, function(dim1, dim2) list(a="foo", b=runif(10))) foo2 <- mlply(dat, function(dim1, dim2) list(a="foo", b=runif(10)))
Jean On Wed, Jun 5, 2013 at 12:33 AM, Murat Tasan <mmu...@gmail.com> wrote: > hi all -- let's say i have the following simplified plyr code: > > > factor_table <- data.frame(dim1 = 1:10, dim2 = 1:4) > > foo <- maply(factor_table, function(dim1, dim2) list(a = "foo", b = > runif(10))) > > foo will now be a 10 x 4 x 2 array (of mode 'list'), and i'll have to > access a "b" element like so: > > foo[[1,1,"b"]] > > if i replace the anonymous function with another that returns a > variable-length list, however, foo will be a 10 x 4 array (again of mode > 'list'), and i'll have to access a "b" element like so: > > foo[[1,1]]$b ## or foo[[1,1]][["b"]] > > i tend to prefer this latter approach, since it's agnostic to the called > function in the maply loop, and thus makes downstream coding more > consistent (in case upstream functions change, the addressing scheme > required to recover that function's various return values is somewhat > uniform). > > does anyone know if we can "force" plyr to _not_ try to simplify along the > inner function's return value length when using the _aply family of calls? > > cheers, > > -m > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.