[Rd] apply() returning a list?

From: David A. Johnston <dajohnston_at_ucdavis.edu>
Date: Tue, 19 Jul 2011 16:34:53 -0700 (PDT)

Hi devel list,

I searched for past posts about this issue and found none, so my apologies if this has been addressed before.

The sapply() function has an argument 'simplify', and the mapply() function has an argument 'SIMPLIFY'. I am surprised that the apply() argument does not have a similar argument. Is there a reason for this?

Here's a simple example:
> x = matrix(1:12, 3, 4)
> apply(x, 1, sum)

[1] 22 26 30

This is what I would like to see:
> apply(x, 1, sum, simplify = FALSE)

[1] 22

[1] 26

[1] 30

Looking at the function definition of apply(), I imagine it wouldn't be too hard to add such an argument. Add an argument 'simplify' with default value TRUE, and include the following line in the function definition. if(simplify == FALSE) return (ans)

Is this a good idea? Would this be a good addition to R's apply() function? Are there stability issues in making this change (for example, what if some previous code threw a 'simplify' argument into the '...')?


-David Johnston

View this message in context: http://r.789695.n4.nabble.com/apply-returning-a-list-tp3679619p3679619.html
Sent from the R devel mailing list archive at Nabble.com.

R-devel_at_r-project.org mailing list
Received on Wed 20 Jul 2011 - 11:31:13 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jul 2011 - 16:10:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive