[Solved] Convert text file to matrix [closed]


I will try to guess what is asked.

Assuming that your data frame is named df, you can convert each column to matrix and put it in list using lapply(). For example, I converted to matrix with two columns.

seq_len(ncol(df) will make sequence of numbers from 1 to number of columns, so conversion will iterate though all columns. Then matrix() convert each column to matrix.

lapply(seq_len(ncol(df)),function(i) matrix(df[,i],ncol=2))
[[1]]
          [,1]      [,2]
[1,] 0.1682512 0.1589936
[2,] 0.1583613 0.1583613
[3,] 0.2294395 0.1401881

[[2]]
          [,1]      [,2]
[1,] 0.1654002 0.1563962
[2,] 0.1423133 0.1283551
[3,] 0.1913303 0.1068051

[[3]]
          [,1]      [,2]
[1,] 0.2558522 0.3320734
[2,] 0.2304359 0.1847167
[3,] 0.2934963 0.1893830

0

solved Convert text file to matrix [closed]