R/matvec.R

Defines functions vecmat matvec

Documented in matvec vecmat

matvec <- function(M,v) {
#	Multiply the columns of matrix by the elements of a vector,
#	i.e., compute M %*% diag(v)
#	Gordon Smyth
#	5 July 1999
#
	v <- as.vector(v)
	M <- as.matrix(M)
	if(length(v)!=dim(M)[2]) stop("matvec: Dimensions do not match")
	t(v * t(M))
}

vecmat <- function(v,M) {
#	Multiply the rows of matrix by the elements of a vector,
#	i.e., compute diag(v) %*% M
#	Gordon Smyth
#	5 July 1999
#
	v <- as.vector(v)
	M <- as.matrix(M)
	if(length(v)!=dim(M)[1]) stop("vecmat: Dimensions do not match")
	v * M
}

Try the statmod package in your browser

Any scripts or data that you put into this service are public.

statmod documentation built on Jan. 6, 2023, 5:14 p.m.