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 ________________________________
How to get standard deviation of rows in a matrix
4 messages · Jagarlamudi, Choudary, Sundar Dorai-Raj, Tobias Verbeke +1 more
Jagarlamudi, Choudary wrote on 3/9/2005 1:49 PM:
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.
This has come up several times in the past and a quick search of the archives would have lead you to: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/34169.html HTH, --sundar
On Wed, 9 Mar 2005 13:49:44 -0600
"Jagarlamudi, Choudary" <choudary.jagar at 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
On Wed, 9 Mar 2005 13:49:44 -0600, "Jagarlamudi, Choudary" <choudary.jagar at 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,])
This doesn't extract the rows, it just returns the same matrix. As the man page for sd says, when applied to a matrix it calculates the standard deviation of each column. What you want to do is to use the apply function. Rows are the first dimension, so you would use apply(genes, 1, sd) Duncan Murdoch