Hey Morris,
You are doing it correctly as is. The pheatmap row-scaling function is the following:
pheatmap.scale <- function(x) {
m = apply(x, 1, mean, na.rm = T)
s = apply(x, 1, sd, na.rm = T)
return((x - m) / s)
}
Let's create random data:
randomdata <- matrix(rexp(2000000, rate=.1), ncol=2000)
Now let's scale with pheatmap()
's row-scaling function:
randomdata.scaled <- pheatmap.scale(randomdata)
Now check the mean and sd of each row:
all(round(apply(randomdata.scaled, 1, mean), 3) == 0)
[1] TRUE
all(round(apply(randomdata.scaled, 1, sd), 3) == 1)
[1] TRUE
---------------------------
Note that this is exactly the same as scaling outside of pheatmap()
, like this:
randomdata.scaled <- t(scale(t(randomdata)))
all(round(apply(randomdata.scaled, 1, mean), 3) == 0)
[1] TRUE
all(round(apply(randomdata.scaled, 1, sd), 3) == 1)
[1] TRUE
------------------------------
So —don't worry— you are doing it correctly.
Kevin