[R] question about apply function
Andris Jankevics
andza at osi.lv
Fri Dec 8 09:36:37 CET 2006
Dear R-Users,
For example i have a data matrix with five samples and three variables.
DATA <- matrix(c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5),nrow=5,ncol=3,byrow=TRUE)
colnames (DATA) <- c("V1","V2","V3")
rownames (DATA) <- c("S1","S2","S3","S4","S5")
I want to normalize all samples to same sum of variables:
NormFun <- function (i) {(i*(1/sum(i)))}
Dnorm <- apply(DATA,1,NormFun)
Why I am getting tranposed matrix Dnorm? And with my experimental data (with
32k variables) i am getting a slighty different results from:
apply(DATA,1,NormFun)
apply(t(DATA),2,NormFun)
Thankyou,
Andris Jankevics
More information about the R-help
mailing list