size: Vector, Matrix or Data.Frame Size

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

View source: R/size.R

Description

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

Usage

1
  size(x = NULL, n = NULL)

Arguments

x

A R object.

n

A integer indicating the dimension of interest.

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.

Value

Returns a vector or list of dimensions.

Author(s)

Sebastien Bihorel (sb.pmlab@gmail.com)

See Also

dim

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  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)

Example output

Loading required package: Matrix
[1] 0 0
[1] 1 1
[1] 1 1
[1] 6
[1] 4 5
[1] 2 5 2 2
[1] NA
[[1]]
[1] 1 1

[[2]]
[1] 1 6

[[3]]
[1] 4 5

[[4]]
[1] 2 5 2 2

[[5]]
[1] 6 2

optimbase documentation built on Jan. 27, 2022, 1:14 a.m.