Create list from each column of matrix in R -


i have matrix m , want create 3 lists each list contains row names of matrix m means fro examle fisrt list, want have m[, 1]$a = 1 , m[ ,1]$b = 2. how can in r each column?

    m       [,1] [,2] [,3]      1    3    5   b    2    4    6 

i have tried code, it's not desire result

  > list(m[, 1])   [[1]]    b     1 2 

this create list of lists:

apply(m, 2, as.list) 

and if matrix had colnames, used names of top-level list:

m <- matrix(1:6, nrow = 2, dimnames = list(c("a", "b"), c("c1", "c2", "c3"))) apply(m, 2, as.list) # $c1 # $c1$a # [1] 1 # # $c1$b # [1] 2 # # # $c2 # $c2$a # [1] 3 # # $c2$b # [1] 4 # # # $c3 # $c3$a # [1] 5 # # $c3$b # [1] 6 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -