[R] Calculating "row standard deviations"

Mark Na mtb954 at gmail.com
Tue Jun 23 00:19:54 CEST 2009


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




More information about the R-help mailing list