[R] how to export data in the order

Stephen D. Weigand weigand.stephen at charter.net
Thu May 19 05:52:10 CEST 2005


On May 18, 2005, at 10:10 PM, Nongluck Klibbua wrote:

> hi all,
> My data is y[j,k] where j=1,...5, k=1,....,10 and when I use
> cat(y,file="c:data.txt",sep="\n"). The data is coming out into the
> data.txt is
> y[1,1],y[2,1],....,y[5,1],y[2,1],y[2,2],....,y[5,2],.....,y[j,k]. How I
> can export the data by my data is
> y[1,1],y[1,2],...y[1,5],y[2,1],[2,2],.....y[j,k].
> Appreciate your time.
> nongluck

Nongluck,

Here's an illustration of a way to get this:

y <- matrix(c(11,12,13,21,22,23), byrow = TRUE, ncol = 3)
print(y)

      [,1] [,2] [,3]
[1,]   11   12   13
[2,]   21   22   23

cat(y, sep = ",") # not what's wanted
11,21,12,22,13,23

cat(t(y), sep = ",") # cat the transpose of y
11,12,13,21,22,23    # better!

Best,

Stephen




More information about the R-help mailing list