[英]Reading multiple matrices from the same file in R
I know you can use read.table
to read one matrix from a file, but I would like to read two matrices of the same size ( m
by n
) from one file in R and put them in two separate R variables. 我知道您可以使用
read.table
从文件中读取一个矩阵,但是我想从R中的一个文件中读取两个大小相同( m
× n
)的矩阵,并将它们放入两个单独的R变量中。
For example, this file contains two 3 by 2 matrices: 例如,此文件包含两个3 x 2矩阵:
6 3
2 5
5 4
4 3
6 3
3 4
Here is my shot at it. 这是我的照片。
split(read.table("data.txt"), gl(2, 3, labels=c("x1", "x2")))
It should be easy to generalize this and wrap it up into a function. 将其概括并包装成一个函数应该很容易。
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.