MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #3690] Add a 'drop' parameter, set to FALSE by default, to apply() #1835

Open MichaelChirico opened 4 years ago

MichaelChirico commented 4 years ago

From: a.buness@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::> 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.


METADATA

MichaelChirico commented 4 years ago

From: Peter Dalgaard BSA <p.dalgaard@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::>> a.buness@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::> 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
<CENSORING FROM DETECTED PHONE NUMBER ONWARDS; SEE BUGZILLA>


METADATA

MichaelChirico commented 4 years ago

From: Patrick Burns <pburns@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::>> 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@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::>-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@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::> 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?

METADATA

MichaelChirico commented 4 years ago

From: A.Buness@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::>-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.


METADATA

MichaelChirico commented 4 years ago

NOTES: add drop=FALSE to apply()


METADATA

MichaelChirico commented 4 years ago

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


METADATA