Learn R Programming

svdvisual (version 1.1)

doublemean: Double mean matrix

Description

This function returns the double mean matrix of an input matrix

Usage

doublemean(x)

Arguments

x
The input matrix. Make sure this is a matrix object

Value

  • The double mean matrix

Details

This function calculates the mean of each row, each column and the overall mean within the input matrix. If the matrix has dimension m x n, this function will return a m x n matrix, where each cell is the sum of the row mean and the column mean, subtract by the overall mean.

Let X be the $m \times n$ input matrix, $x_{ij}$ is the i, j cell within it. Let D be the resulting matrix of this program, and $d_{ij}$ as the corresponding cell. Let $$r_i =\frac{1}{n}\sum_{j=1}^n x_{ij}, c_j=\frac{1}{m}\sum_{i=1}^m x_{ij}, o=\frac{1}{mn}\sum_{i=1}^m\sum_{j=1}^n x_{ij}.$$ Then $$d_{ij}=r_i+c_j-o;$$

See Also

See Also in svd, apply, columnmean, rowmean, overallmean.

Examples

Run this code
#generate a random matrix
x<-matrix(rnorm(100), nrow=20);

#calculate the row mean matrix
y<-doublemean(x);
y

Run the code above in your browser using DataLab