arrays - Passing as a variable the individual columns of individual matrices in a list of matrices -


i want pass columns in various matrices loop.

if 2 matrices had same number of columns, might this:

mat1 = matrix(rep(1:25), 5,5) mat2 = matrix(rep(26:50), 5,5) array.mat = array(c(mat1,mat2), dim=c(5,5,2)) mat1.ncol = ncol(mat1) mat2.ncol = ncol(mat2) mat.ncol = c(mat1.ncol, mat2.ncol) mat.ncol array.mat (dimi in 1:2){   dim.col = mat.ncol[dimi]     (coli in 1:dim.col){       st = shapiro.test(array.mat[,coli,dimi])$p.value         if(st > .001){           array.mat[,coli,dimi] = log(array.mat[,coli,dimi]) }}} 

but, data don't have same number of columns, i'd use list of matrices instead.

mat1 = matrix(rep(1:10), 5,2) mat2 = matrix(rep(26:50), 5,5) list.mat=list(a=mat1, b=mat2) list.mat 

but can't figure out how i'd pass columns of matrices?

list.mat$a[1:5]  

gives first column of first matrix, how pass $a , [startindex:endindex] in loop? other answers see tend pass ith element (e.g., column) of both matrices. need keep 2 matrices (a , b) separate later computations, want them (the list of 2 matrices) these types of loops. once again, i'm thinking incorrectly. thoughts.

can use numeric indices? e.g., matrix 1, column 1: list.mat[[1]][,1]

in loop:

for (m in 1:2) {   (i in 1:ncol(list.mat[[m]])) {     cat('here matrix', m, ', columnn', i, '\n')     print(list.mat[[m]][,i])   } } 

result:

here matrix 1 , columnn 1  [1] 1 2 3 4 5 here matrix 1 , columnn 2  [1]  6  7  8  9 10 here matrix 2 , columnn 1  [1] 26 27 28 29 30 here matrix 2 , columnn 2  [1] 31 32 33 34 35 here matrix 2 , columnn 3  [1] 36 37 38 39 40 here matrix 2 , columnn 4  [1] 41 42 43 44 45 here matrix 2 , columnn 5  [1] 46 47 48 49 50 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -