I'm facing a problem while scaling(z-transform) the row values of a numeric gene expression data matrix to be used for a PCA analysis. Here's a to generate a toy matrx of 6 samples and 20 genes:
rm(list=ls()) set.seed(12345) my.mat <- matrix(rnorm(120,0,0.5),nrow=6,byrow=TRUE) rownames(my.mat) <- paste("s",1:6,sep="") colnames(my.mat) <- paste("g",1:20,sep="") dim(my.mat) # 6 20#six rows 20 columns z.mat <- apply(my.mat, MARGIN = 1, FUN = scale ) dim(z.mat) #20 6 # The matrix gets transposed##!!!!
to get the correct matrix for which all the row means equal zeo and std. deviation 1, I've to transpose t(z.mat) again. Am I making some silly mistake somewhere?