Hi Gabor, In strictly reading the help files for both nrow() and row(), the 'x' argument in the former case is "a vector, array, data frame, or NULL.", whereas in the latter case it is "a matrix-like object, that is one with a two-dimensional dim.".
Thus, I would expect row() to fail on a >= 3-dimensional array, as your example shows. In reading the help file for slice.index(), there is the following in the See Also section: "row and col for determining row and column indexes; in fact, these are special cases of slice.index corresponding to MARGIN equal to 1 and 2, respectively when x is a matrix." further differentiating the behavior of row() and col() as more specific implementations in the 2-dimensional case. To my read then, the difference in behavior appears to be intentional and expected. Regards, Marc Schwartz -----Original Message----- From: R-devel <[email protected] <mailto:[email protected]>> on behalf of Gabor Grothendieck <[email protected] <mailto:[email protected]>> Date: Sunday, September 8, 2024 at 7:31 AM To: "[email protected] <mailto:[email protected]>" <[email protected] <mailto:[email protected]>> Subject: [Rd] Inconsistency between row and nrow In the following nrow provides the expected result but row gives an error. I would have thought that they would both work or both fail. aa <- array(dim = 5:3) nrow(aa) ## [1] 5 row(aa) ## Error in row(aa) : a matrix-like object is required as argument to 'row' # this does work: slice.index(aa, 1) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ [email protected] <mailto:[email protected]> mailing list https://stat.ethz.ch/mailman/listinfo/r-devel <https://stat.ethz.ch/mailman/listinfo/r-devel> ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
