size: Size

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

Description

Replicates some of the functionality of MATLAB's size function.

Usage

1
size(x, dim=NA)

Arguments

x

An R object accepted by dim, or a vector

dim

An integer specifying the size of the dimension to return.

Value

If x is anything other than a vector the result from size will be identical to dim (i.e. a vector of mode integer).

If is.vector(x) == TRUE then size will return a vector equal to c(1,length(x)) (i.e. 1 row and n columns).

Note

is.vector returns FALSE if x is a factor. This seems a little odd, but for now, if you provide a factor then size will return NULL with a warning.

Author(s)

Daniel Pritchard

See Also

dim, is.vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
dat_a <- c(1,2,3,4,5)
dat_b <- matrix(c(1,2,3,4,5,6), nrow=2)

size(2)			# 1 1
size(dat_a) 	# 1 5
size(dat_b)		# 2 3
size(as.factor(dat_a)) # NULL, with a warning

stopifnot(all(size(dat_b)==dim(dat_b)))

# Just the number of columns
size(dat_b, dim=2)
# Which is the same as...
size(dat_b)[2]

dpritchard/dgmisc documentation built on May 15, 2019, 1:50 p.m.