darpich
darpich

Reputation: 137

Write a row of a matrix in a file

I have a simple matrix with n rows and m columns:

param <- mat.or.vec(n,m)

(n and m are variables defined earlier.)

I then populate the matrix with random numbers so the matrix is not empty.

I would like to write each row in a different file, with each entry separated by a tab. So for example for the first row I use:

write.table(param[1,],"param1.txt",sep="\t",row.names=FALSE, col.names=FALSE)

However, when I try this, I get a file where the row is in column form. That is, instead of the desired result:

a b c d

I get

a
b
c
d

I really don't understand why I get such a thing... Any help will be greatly appreciated!

Upvotes: 1

Views: 75

Answers (1)

Yorgos
Yorgos

Reputation: 30445

write.table(param[1,,drop=FALSE],"param1.txt",sep="\t",row.names=FALSE, col.names=FALSE)

Upvotes: 1

Related Questions