Learn R Programming

optimbase (version 1.0-10)

size: Vector, Matrix or Data.Frame Size

Description

size is a utility function which determines the dimensions of vectors (coerced to matrices), matrices, arrays, data.frames, and list elements.

Usage

size(x = NULL, n = NULL)

Arguments

x

A R object.

n

A integer indicating the dimension of interest.

Value

Returns a vector or list of dimensions.

Details

size is a wrapper function around dim. It returns the n^th dimension of x if n is provided. If n is not provide, all dimensions will be determined. If x is a list, n is ignored and the dimensions of all elements of x are recursively determined.

See Also

dim

Examples

Run this code
# NOT RUN {
  a <- 1
  b <- letters[1:6]
  c <- matrix(1:20,nrow=4,ncol=5)
  d <- array(1:40, dim=c(2,5,2,2))
  e <- data.frame(a,b)
  f <- list(a,b,c,d,e)

  size(NULL) # 0 0
  size(NA)   # 1 1
  size(a)    # 1 1
  size(b,2)  # 6
  size(c)    # 4 5
  size(d)    # 2 5 2 2
  size(e,3)  # NA
  size(f)
# }

Run the code above in your browser using DataLab