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

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Thu 10 Mar 2005 - 07:30:53 EST


You should read ?var and ?sd more carefully. For a data frame or a matrix, var() returns the covariance matrix of the columns, whereas sd() returns the standard deviations of the columns. If you want standard deviations of the rows, you need to transpose the data.

Andy

> From: Jagarlamudi, Choudary
>
> 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.
>
> Choudary Jagarlamudi
> Instructor
> Southwestern Oklahoma State University
> STF 254
> 100 campus Drive
> Weatherford OK 73096
> Tel 580-774-7136
>
> ________________________________
>
>



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:29:38 2005

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