Tena koe Mark I think you might want
apply(datac, 1, mean) i.e., apply the function to the first dimension (rows) rather than the second (columns). HTH ... Peter Alspach > -----Original Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Na > Sent: Tuesday, 23 June 2009 10:20 a.m. > To: r-help@r-project.org > Subject: [R] Calculating "row standard deviations" > > Hi R-helpers, > > I have been struggling with calculating row and column > statistics, e.g. standard deviation. > > I know that > > datac$Mean<-rowMeans(datac,na.rm=TRUE) > will give me row means. > > I have tried to replicate those row means with the apply function: > > datac$Mean2<-apply(datac,2,mean) > > so that I can replace the function argument with "sd" (instead of > mean) to get standard deviations. > > But, I'm running into this error: > > > dim(datac) > [1] 17 271 > > datac$Mean2<-apply(datac,2,mean) > Error in dimnames(x) <- dn : > length of 'dimnames' [2] not equal to array extent > > > Can anyone see what I'm doing wrong? > > Thanks! > > Mark Na > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.