From dwinsemius at comcast.net  Wed Jul 20 17:13:22 2011
From: dwinsemius at comcast.net (David Winsemius)
Date: Wed, 20 Jul 2011 11:13:22 -0400
Subject: [Rd] apply() returning a list?
In-Reply-To: <1311118493785-3679619.post@n4.nabble.com>
References: <1311118493785-3679619.post@n4.nabble.com>
Message-ID: <D9FF0717-ED0D-4892-8ACF-7D241972370E@comcast.net>


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



[Rd] apply() returning a list?
David Winsemius