I am processing a special object -- SliceData object from Matrix_eQTL -- in a loop and I am wondering if it can be re-write by any function in the "apply".
Let me explain it by a toy example. First I create the toy data by the following scripts.
library(MatrixEQTL)
set.seed(5)
gene_mat = matrix(data = rnorm(200000, mean=50, sd=10), nrow = 2000, ncol = 100)
gene = SlicedData$new(gene_mat);
gene$ResliceCombined(200)
Here I have a custom function invnorm
.
invnorm <- function(expression){
return(qnorm((rank(expression, na.last="keep") - 0.5)/sum(!is.na(expression))))
}
And what I want to do is to apply this invnorm
on each row of each slice of gene
object which can be realized by the following scripts
for( sl in 1:length(gene) ){
mat = gene[[sl]]
mat = t(apply(mat, 1, invnorm))
gene[[sl]] = mat
}
So is there any way to re-wrote this loop by any function in the apply
function family? Thank you in advance.