Re: [Rd] simplify2array edge case

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri, 19 Oct 2012 11:09:22 +0200

>>>>> William Dunlap <wdunlap_at_tibco.com> >>>>> on Thu, 11 Oct 2012 18:59:52 +0000 writes:

> Should simplify2array(higher=TRUE) treat 1 by 1 matrices differently than others?
> I expected a 3-dimensional array from all of the following 3 examples, not just the last 2.

    >> str(simplify2array(list(array(11,c(1,1)), array(21,c(1,1))), higher=TRUE))

> num [1:2] 11 21
    >> str(simplify2array(list(array(11:13,c(3,1)), array(21:23,c(3,1))), higher=TRUE))

> int [1:3, 1, 1:2] 11 12 13 21 22 23
    >> str(simplify2array(list(array(11:13,c(1,3)), array(21:23,c(1,3))), higher=TRUE))
> int [1, 1:3, 1:2] 11 12 13 21 22 23

I wrote simplify2array() in order to modularize sapply() and have mapply() and sapply() behave identically and because its utility seemed useful in at least on other case. In the mean time it is also used in the parallel package's *apply() functions.

The distinction of 1 x 1 vs n x n for n >= 2 i.e.,

       if (common.len == 1L) 
            unlist(answer, recursive = FALSE)
        else if (common.len > 1L) 
            array(unlist(answer, recursive = FALSE), dim = c(common.len, 
	          .......
		  ....... )

had really been part of sapply() at the time and hence needed to go into simplify2array() in order to keep sapply() completely back compatible.

Bill, have you looked into optional different behavior?

Martin Maechler, ETH Zurich

> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 19 Oct 2012 - 09:12:37 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 Fri 19 Oct 2012 - 13:30:47 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