Re: [R] How to get standard deviation of rows in a matrix

From: Tobias Verbeke <tobias.verbeke_at_telenet.be>
Date: Thu 10 Mar 2005 - 07:20:42 EST

On Wed, 9 Mar 2005 13:49:44 -0600
"Jagarlamudi, Choudary" <choudary.jagar@swosu.edu> wrote:

> Hi all,
>
> I am trying to find sd of my rows in a matrix and i get column sd inspite of extracting rows.
> I tried to do the sqrt(var(x)) but that did'nt work as well,
>
> Here is my data
>
> genes
> 15 24 63 40
> 25 42 46 35
> 23 53 37 45
> 30 37 50 55
> 40 51 30 48
>
> x<-sd(genes[1:5,])
>
> y<-sqrt(var(genes[1:5,]))
>
> I get 4 sds for the 4 columns instead of 5 sds for my 5 rows.
> Thanks you in advance.

> mymat <- matrix(rnorm(20), 5)
> mymat

           [,1] [,2] [,3] [,4]

[1,] -0.1418666 -0.6754704 -0.2525154 -1.4832003
[2,] -0.2254920  1.8705093 -0.9678318 -0.1108883
[3,]  2.2501392  0.1687349 -0.1279790  0.7055311
[4,]  0.9893453 -0.5924199  0.2410576  0.9001638
[5,] -0.4179559  0.9334556 -0.6501605  0.6148958

> apply(mymat, 1, sd)

[1] 0.6084171 1.2135998 1.0584750 0.7318231 0.7722641

See ?apply

HTH,
Tobias



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Mar 10 21:09:43 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:42 EST