Learn R Programming

statnet.common (version 4.10.0)

wmatrix: A data matrix with row weights

Description

A representation of a numeric matrix with row weights, represented on either linear (linwmatrix) or logarithmic (logwmatrix) scale.

Usage

logwmatrix(
  data = NA,
  nrow = 1,
  ncol = 1,
  byrow = FALSE,
  dimnames = NULL,
  w = NULL
)

linwmatrix( data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL, w = NULL )

is.wmatrix(x)

is.logwmatrix(x)

is.linwmatrix(x)

as.linwmatrix(x, ...)

as.logwmatrix(x, ...)

# S3 method for linwmatrix as.linwmatrix(x, ...)

# S3 method for logwmatrix as.linwmatrix(x, ...)

# S3 method for logwmatrix as.logwmatrix(x, ...)

# S3 method for linwmatrix as.logwmatrix(x, ...)

# S3 method for matrix as.linwmatrix(x, w = NULL, ...)

# S3 method for matrix as.logwmatrix(x, w = NULL, ...)

# S3 method for wmatrix print(x, ...)

# S3 method for logwmatrix print(x, ...)

# S3 method for linwmatrix print(x, ...)

# S3 method for logwmatrix compress_rows(x, ...)

# S3 method for linwmatrix compress_rows(x, ...)

# S3 method for wmatrix decompress_rows(x, target.nrows = NULL, ...)

# S3 method for wmatrix [(x, i, j, ..., drop = FALSE)

# S3 method for wmatrix [(x, i, j, ...) <- value

Value

An object of class linwmatrix/logwmatrix and wmatrix, which is a matrix but also has an attribute w containing row weights on the linear or the natural-log-transformed scale.

Arguments

data, nrow, ncol, byrow, dimnames

passed to matrix.

w

row weights on the appropriate scale.

x

an object to be coerced or tested.

...

extra arguments, currently unused.

target.nrows

the approximate number of rows the uncompressed matrix should have; if not achievable exactly while respecting proportionality, a matrix with a slightly different number of rows will be constructed.

i, j, value

rows and columns and values for extraction or replacement; as matrix.

drop

Used for consistency with the generic. Ignored, and always treated as FALSE.

See Also

rowweights, lrowweights, compress_rows

Examples

Run this code
(m <- matrix(1:3, 2, 3, byrow=TRUE))
(m <- rbind(m, 3*m, 2*m, m))
(mlog <- as.logwmatrix(m))
(mlin <- as.linwmatrix(m))
(cmlog <- compress_rows(mlog))
(cmlin <- compress_rows(mlin))

stopifnot(all.equal(as.linwmatrix(cmlog),cmlin))

cmlog[2,] <- 1:3
(cmlog <- compress_rows(cmlog))
stopifnot(sum(rowweights(cmlog))==nrow(m))

(m3 <- matrix(c(1:3,(1:3)*2,(1:3)*3), 3, 3, byrow=TRUE))
(rowweights(m3) <- c(4, 2, 2))

stopifnot(all.equal(compress_rows(as.logwmatrix(m)), as.logwmatrix(m3),check.attributes=FALSE))
stopifnot(all.equal(rowweights(compress_rows(as.logwmatrix(m))),
                    rowweights(as.logwmatrix(m3)),check.attributes=FALSE))

Run the code above in your browser using DataLab