Skip to content
Prev 267349 / 398502 Next

Standard Deviation of a matrix

Hi!

The sample below should give you what you want:

M = matrix(runif(100), 10, 10)
sd(as.numeric(M))

So the as.numeric command is the key. It transforms the matrix to a 1D
vector. Or alternatively without using as.numeric:

M = matrix(runif(100), 10, 10)
M
dim(M) = 100
M
sd(M)

Here I use the dim command to set the dimensions to a vector of 100 long.

cheers,
Paul
On 08/02/2011 11:07 AM, chakri wrote: