thx for your help!
I have 2 matrices: Mx1 and Mx2 And I would like to make heatmaps using pheatmap by looping on selected matrices in the R environment
I tried:
Matrices_list <- c(Mx1, Mx2)
for( i in Matrices_list_list ){pheatmap(i, filename= "i.pdf")}
but obviously doesn't works The problems is that the Df_list now is a merge of both Mx instead of 2 distinct datasets in which I cant loop. Its looping in each element of the combined Df_list
Desired output:
pheatmap(Mx1, filename="Mx1.pdf")
pheatmap(Mx2, filename="Mx2.pdf")
Thx again for your help :)
A
matrix
is avector
withdim
ension attributes (usually 2D). The use ofc
function on two matrices, removes the dimension attributes and return a single 1 dimensional vector withlength
equal to thelength(Mx1)
+length(Mx2)
.As showed in the comments, if we need to keep the
matrix
as itself store it in alist
withnames
attribute as the object names of the individual matrices. Withdplyr::lst
, by default it generates thenames
of thelist
as object namesRegarding the
for
loop used in OP's postthe
i
is the individual matrix element, which doesn't have any names attribute. This can be otherwise described as afor
each loop i.e. for each element 'x' of 'Matrices_list'. In other languages such asC++
, the for each syntax would beInstead of looping over the object elements, loop over the sequence
or the
names
attribute, extract those elements and the corresponding names to construct the file name.With tidyverse, we can use
imap
oriwalk
with.x
the matrix element and.y
the names of thelist
or the index (if the names are absent)The difference in
imap/iwalk
is thatiwalk
doesn't print the return value on the console.