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
matrixis avectorwithdimension attributes (usually 2D). The use ofcfunction on two matrices, removes the dimension attributes and return a single 1 dimensional vector withlengthequal to thelength(Mx1)+length(Mx2).As showed in the comments, if we need to keep the
matrixas itself store it in alistwithnamesattribute as the object names of the individual matrices. Withdplyr::lst, by default it generates thenamesof thelistas object namesRegarding the
forloop used in OP's postthe
iis the individual matrix element, which doesn't have any names attribute. This can be otherwise described as aforeach 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
namesattribute, extract those elements and the corresponding names to construct the file name.With tidyverse, we can use
imaporiwalkwith.xthe matrix element and.ythe names of thelistor the index (if the names are absent)The difference in
imap/iwalkis thatiwalkdoesn't print the return value on the console.