[R] Cube of Matrices or list of Matrices
Ben Tupper
ben.bighair at gmail.com
Mon Jan 19 16:36:53 CET 2015
Hi,
On Jan 18, 2015, at 4:36 PM, Karim Mezhoud <kmezhoud at gmail.com> wrote:
> Dear All,
> I am trying to get correlation between Diseases (80) in columns and
> samples in rows (UNEQUAL) using gene expression (at less 1000,numeric). For
> this I can use CORREP package with cor.unbalanced function.
>
> But before to get this final matrix I need to load and to store the
> expression of 1000 genes for every Disease (80). Every disease has
> different number of samples (between 50 - 500).
>
> It is possible to get a cube of matrices with equal columns but unequal
> rows? I think NO and I can't use array function.
>
> I am trying to get à list of matrices having the same number of columns but
> different number of rows. as
>
> Cubist <- vector("list", 1)
> Cubist$Expression <- vector("list", 1)
>
>
> for (i in 1:80){
>
> matrix <- function(getGeneExpression[i])
> Cubist$Expression[[Disease[i]]] <- matrix
>
> }
>
> At this step I have:
> length(Cubist$Expression)
> #80
> dim(Cubist$Expression$Disease1)
> #526 1000
> dim(Cubist$Expression$Disease2)
> #106 1000
>
> names(Cubist$Expression$Disease1[4])
> #ABD
>
> names(Cubist$Expression$Disease2[4])
> #ABD
>
> Now I need to built the final matrices for every genes (1000) that I will
> use for CORREP function.
>
> Is there a way to extract directly the first column (first gene) for all
> Diseases (80) from Cubist$Expression? or
>
I don't understand most your question, but the above seems to be straight forward. Here's a toy example:
# make a list of matrices, each with nCol columns and differing
# number of rows, nRow
nCol <- 3
nRow <- sample(3:10, 5)
x <- lapply(nRow, function(x, nc) {matrix(x:(x + nc*x - 1), ncol = nc, nrow = x)}, nCol)
x
# make a simple function to get a single column from a matrix
getColumn <- function(x, colNum) {
return(x[,colNum])
}
# use the function to get the column from each matrix
col1 <- lapply(x, getColumn, 1)
col1
Does that help answer this part of your question? If not, you may need to create a very small example of your data and post it here using the head() and dput() functions.
Ben
> I need to built 1000 matrices with 80 columns and unequal rows?
>
> Cublist$Diseases <- vector("list", 1)
>
> for (k in 1:1000){
> for (i in 1:80){
>
> Cublist$Diseases[[gene[k] ]] <- Cubist$Expression[[Diseases[i] ]][k]
> }
>
> }
>
> This double loops is time consuming...Is there a way to do this faster?
>
> Thanks,
> karim
> Ô__
> c/ /'_;~~~~kmezhoud
> (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ
> http://bioinformatics.tn/
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list