Reputation: 1034
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.
For example, this file contains two 3 by 2 matrices:
6 3
2 5
5 4
4 3
6 3
3 4
Upvotes: 0
Views: 506
Reputation: 134
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.
Upvotes: 1