Learn R Programming

iemisc (version 0.5.0)

size: Size of R objects (GNU Octave/MATLAB compatible)

Description

Provides the dimensions of R objects in a manner compatible with GNU Octave/MATLAB. This function is the same as size, except this size can find the size of character vectors too. Some documentation from size.

Usage

size(x, k)

Arguments

x
An R object (array, vector, or matrix)
k
integer specifying a particular dimension

Value

  • "Return the number of rows and columns of the object x as a numeric vector. If given a second argument, size will return the size of the corresponding dimension." Source: Eaton.

encoding

UTF-8

source

pracma size function definition - R package pracma created and maintained by Hans Werner Borchers. See interp1.

References

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 42.

See Also

dim, size

Examples

Run this code
library(iemisc)
# Examples from GNU Octave size
object1 <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, ncol = 2, byrow = TRUE)
size(object1)

source("http://gsubfn.googlecode.com/svn/trunk/R/list.R")
list[nr, nc] <- size(matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, ncol = 2,
                byrow = TRUE))

size(matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, ncol = 2, byrow = TRUE), 2)

# Examples from pracma size
size(1:8)

size(matrix(1:8, 2, 4))

size(matrix(1:8, 2, 4), 2)

size(matrix(1:8, 2, 4), 3)

ss <- "object"
size(ss)


# check against GNU Octave
library(RcppOctave) # requires Octave (>= 3.2.4) and its development files
o_source(text = "
\% Examples from GNU Octave size
object1 = [1, 2; 3, 4; 5, 6];
size(object1)

[nr, nc] = size([1, 2; 3, 4; 5, 6])

size([1, 2; 3, 4; 5, 6], 2)

\% Examples from pracma size
size(1:8)

object2 = [1 3 5 7; 2 4 6 8];

size(object2)

size(object2, 2)

size(object2, 3)

ss = 'object';
size(ss)
")

Run the code above in your browser using DataLab