Re: [Rd] apply() returning a list?

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 20 Jul 2011 11:13:22 -0400

On Jul 19, 2011, at 7:34 PM, David A. Johnston wrote:

> 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]]
> [1] 22
>
> [[2]]
> [1] 26
>
> [[3]]
> [1] 30
>

Probably no one thought it was that difficult to type the more concise and equally expressive:

 > as.list(apply(x, 1, sum))
[[1]]
[1] 22

[[2]]
[1] 26

[[3]]
[1] 30

-- 
David Winsemius, MD
West Hartford, CT

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 20 Jul 2011 - 15:15:35 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 Thu 21 Jul 2011 - 09:00: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