iemisc (version 0.9.8)

numel: Number of elements (GNU Octave/MATLAB compatible)

Description

Obtain the number of elements of R objects [arrays, matrices, and vectors (including lists)] in a manner compatible with GNU Octave/MATLAB. Some documentation from length.

Usage

numel(x, ...)

Arguments

x

An R object (array, matrix, vector)

...

R objects (indices idx1, idx2, ...)

Value

"Return the number of elements in the R object x. Optionally, if indices idx1, idx2, ... are supplied, return the number of elements that would result from the indexing a(idx1, idx2, ...)." Source: Eaton page 41.

References

  1. Samit Basu (2002-2006). FreeMat v4.0, http://freemat.sourceforge.net/.

  2. John W. Eaton, David Bateman, and S<U+00F8>ren Hauberg (2009). GNU Octave version 3.0.1 manual: a high-level interactive language for numerical computations. CreateSpace Independent Publishing Platform. ISBN 1441413006, URL http://www.gnu.org/software/octave/doc/interpreter/. Page 41.

See Also

numel, numel, size, length

Examples

Run this code
# NOT RUN {
library("iemisc")
import::from(pracma, ones)
xx <- list(1:26, 1:10)
numel(xx)

# Examples from GNU Octave numel
a <- 1
b <- ones(2, 3)
numel(a, b)

a <- 2
b <- ones(2, 3)
c <- ones(3, 4)
numel(a, b)
numel(a, b, c)

f <- matrix(c(10, 12, 23, 21, 62, 93), nrow = 2, ncol = 3, byrow = TRUE)
g <- c(2, 4)
numel(f, g)


# }
# NOT RUN {
# check against GNU Octave
library(RcppOctave) # requires Octave (>= 3.2.4) and its development files
o_source(text = "
xx = {1:26, 1:10}

\<!-- % Examples from GNU Octave numel -->
a = 1;
b = ones(2, 3);
numel(a, b)

a = 2;
b = ones(2, 3);
c = ones(3, 4);
numel(a, b)
numel(a, b, c)

f = [10 12 23; 21 62 93];
g = [2 4];
numel(f, g)
")
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab