Bug 3690 - Add a 'drop' parameter, set to FALSE by default, to apply()
Summary: Add a 'drop' parameter, set to FALSE by default, to apply()
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: old
Hardware: All Other
: P5 normal
Assignee: Jitterbug compatibility account
URL:
Depends on:
Blocks:
 
Reported: 2003-08-08 18:50 UTC by Jitterbug compatibility account
Modified: 2015-04-26 10:26 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2003-08-08 18:50:27 UTC
From: a.buness@dkfz.de
Full_Name: Andreas Buness
Version: 1.7.1
OS: Unix
Submission from: (NULL) (193.174.53.122)


I would like to ask you to enhance the apply function
with an option drop=FALSE similar to the one existing
for subsetting of arrays. Or any other mechanism to get
control on the dimensionality of an object resulting 
from an apply call. This could facilitate more robust 
programming.


Comment 1 Jitterbug compatibility account 2003-08-08 19:29:25 UTC
From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
a.buness@dkfz.de writes:

> Full_Name: Andreas Buness
> Version: 1.7.1
> OS: Unix
> Submission from: (NULL) (193.174.53.122)
> 
> 
> I would like to ask you to enhance the apply function
> with an option drop=FALSE similar to the one existing
> for subsetting of arrays. Or any other mechanism to get
> control on the dimensionality of an object resulting 
> from an apply call. This could facilitate more robust 
> programming.

Don't you mean simplify=TRUE similar to sapply()? This has been
suggested a couple of times. Or how do you intend 'drop' to work?

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
Comment 2 Jitterbug compatibility account 2003-08-09 00:45:53 UTC
From: Patrick Burns <pburns@pburns.seanet.com>
I'm not sure if this is the original wish or not, but I have run
into the following situation:

I apply a function to a matrix, but the operation fails because
the function expects a matrix (which in my mind is the one
column or row at each go). The function doesn't see it that
way because it only gets the data as a vector.

Personally, I'd favor forcing the user to write a wrapper function
that does as.matrix (possibly with a transpose) rather than cluttering
up apply.  

Patrick Burns

Burns Statistics
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Peter Dalgaard BSA wrote:

>a.buness@dkfz.de writes:
>
>  
>
>>Full_Name: Andreas Buness
>>Version: 1.7.1
>>OS: Unix
>>Submission from: (NULL) (193.174.53.122)
>>
>>
>>I would like to ask you to enhance the apply function
>>with an option drop=FALSE similar to the one existing
>>for subsetting of arrays. Or any other mechanism to get
>>control on the dimensionality of an object resulting 
>>from an apply call. This could facilitate more robust 
>>programming.
>>    
>>
>
>Don't you mean simplify=TRUE similar to sapply()? This has been
>suggested a couple of times. Or how do you intend 'drop' to work?
>
>  
>



Comment 3 Jitterbug compatibility account 2003-08-11 13:15:27 UTC
From: A.Buness@dkfz-heidelberg.de
I will try to clarify my wish regarding apply.

My wish is related to the dimension attribute of an object.
Of course by the nature of apply the dimension may change,
but as you can see in my artifical examples below the same 
apply-operation applied to a matrix does behave differently 
to that respect.

> dim(matrix(0,nrow=1,ncol=1))
[1] 1 1
> dim(apply(matrix(0,nrow=1,ncol=1),1,function(x) return(x)))
NULL


> dim(matrix(0,nrow=2,ncol=1))
[1] 2 1
> apply(matrix(0,nrow=2,ncol=1),1,function(x) return(x))
[1] 0 0
> dim(apply(matrix(0,nrow=2,ncol=1),1,function(x) return(x)))
NULL


> dim(matrix(0,nrow=1,ncol=2))
[1] 1 2
> dim(apply(matrix(0,nrow=1,ncol=2),1,function(x) return(x)))
[1] 2 1


In these examples I would expect "matrix-dimensions" for 
all cases instead of no dimensions at all in the first
two cases. A follow up apply-operation (expecting a matrix 
like object will fail) and programming is laborious.
This is the reason why I am asking for an extension
of apply like "drop=FALSE" as it exists for subsetting 
of arrays.
Comment 4 Jitterbug compatibility account 2004-09-14 12:23:00 UTC
NOTES:
 add drop=FALSE to apply()
Comment 5 Jitterbug compatibility account 2004-09-14 14:22:37 UTC
Audit (from Jitterbug):
Fri Aug 15 15:55:55 2003	dmurdoch	moved from incoming to wishlist
Tue Sep 14 09:22:37 2004	ripley	changed notes