Help us understand the problem. What is going on with this article?

R: Saving and Reading Matrix in R

More than 5 years have passed since last update.

R has a very difficult, yet probally extremely powerful scheme called "dataframe". Because of its intrication, saving and reading can be difficult for a beginner like me.

Suppose Mat is Matrix. The following will save in the text file that is readable from Matlab.

write.table(Mat, "Matrix", sep = ",", row.names = FALSE, col.names = FALSE)

Howver, the matrix saved this way cannot be read from R. When R reads a text file, it considers the column as "names" in data.frame attributes. Without the prescribed names, R will confuse names with values.

data.frame attributes:
names: category. e.g. Sex
class: class of the category "Name". e.g. Male
row.names: subjects. e.g. Josh, Mary

Instead, we shall

write.matrix("Matrix". sep = ", ")

When you do this, we can recover the file with

M = read.csv("Matrix", header = FALSE)

M extracted this way, however, is data.frame.

its columns are given the name Vk, and
its rows are enumerated.

To extract the column, simply call M$Vk.
To extract the row, as.numeric(M[k, ]) will do.
You might want to prepare a separate matrix into which you copy thes numerics.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away