iemisc (version 0.9.8)

length_octave: Length of R objects (GNU Octave/MATLAB compatible)

Description

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

Usage

length_octave(x)

Arguments

x

An R object (array, matrix, vector)

Value

Return the length of the object x as an integer. "The length is 0 for empty objects, 1 for scalars (in R, a vector of length 1), and the number of elements (in R, the length) for vectors. For matrix objects, the length is the number of rows or columns, whichever is greater (this odd definition is used for compatibility with MATLAB)." Source: Eaton.

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

length, lengths, size, size

Examples

Run this code
# NOT RUN {
library("iemisc")
import::from(pracma, ones)
# Example from pracma isempty
object1 <- matrix(0, 1, 0)
length_octave(object1)

object2 <- 2
length_octave(object2)

object3 <- 1:10
length_octave(object3)

object4 <- ones(3, 4)
length_octave(object4)

object5 <- "ss"
length_octave(object5)

object6 <- list(letters, b <- 2)
length_octave(object6)


# }
# NOT RUN {
# check against GNU Octave
library(RcppOctave) # requires Octave (>= 3.2.4) and its development files
o_source(text = "
object1 = [];
length(object1)

object2 = 2;
length(object2)

object3 = 1:10;
length(object3)

object4 = ones(3, 4);
length(object4)

object5 = 'ss';
length(object5)
")
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab