Re: [R] writing a matrix in a file

From: Sean Anderson <lists_at_seananderson.ca>
Date: Wed, 02 Jun 2010 10:45:01 -0300

On 10-06-02 10:34 AM, amir wrote:
> I want to write a matrix (n*m) in a file (Text file) such that the file
> will be as Result file (below).
> I use the below command but it write all numbers in one column,
>
>> write(paste(matrixname),file="test.txt",append=TRUE)
>
> how can I do this?
> ...
> Matrix:
> [,1] [,2] [,3] [,4] [,5] [,6]
> [1,] 5 5 -1 -1 -1 -1
> [2,] 8 8 2 7 6 5
> [3,] 6 6 8 2 7 5

x <- matrix(1:12, nrow = 4)
sink("test.txt")
cat("Matrix:\n")
x
sink()

Also look at ?write.table

Sean



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 02 Jun 2010 - 13:53:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jun 2010 - 14:10:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive