[R] The match of "ave()" for "FUN=SD"
Felix Wave
felix-wave at vr-web.de
Tue May 8 17:57:15 CEST 2007
Hello,
I have many subsets of x. I want to get the standard deviation
for each subset with the same factor levels. For "FUN=mean" and
"FUN=median" I am using "ave()".
Can anybody tell me the match of "ave()" for using "FUN=SD"?
At the beginning I used aggregate(), also for mean and median. But
aggregegate make ""arithmetical errors"" in computing huge records.
Thank's a lot.
Felix
R-CODE:
-------
MEAN <- ave(INPUT[,3], INPUT[,1], INPUT[,2], FUN = mean)
mMEAN <- matrix( c(INPUT[,1], INPUT[,2], MEAN), ncol=3, byrow=FALSE)
SD <- na.omit( aggregate(INPUT[,3], by=list(INPUT[,2],INPUT[,1] ), FUN=sd ) )
mSD <- matrix( c( SD[,2], SD[,1], SD[,3]), ncol=3, byrow=FALSE)
mSD[,1] <- (mSD[,1] - 1 ) #eleminate the converting-fault list-> matrix
mSD[,2] <- (mSD[,2] - 1 ) / 10 #eleminate the converting-fault list-> matrix
the arithmetical errors:
------------------------
list -> matrix
0 -> 1 1
1 -> 2
2.1 -> 22
3.5 -> 36
More information about the R-help
mailing list