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

Description Usage Arguments Value Author(s) References See Also Examples

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

1

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.

Author(s)

Irucka Embry, Samit Basu (FreeMat)

References

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

  2. John W. Eaton, David Bateman, and Sø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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)
")

## End(Not run)

iemisc documentation built on Aug. 2, 2020, 9:07 a.m.