[R] Flip Matrix form file?

From: Chris82 <rubenbauar_at_gmx.de>
Date: Wed, 23 Jul 2008 09:23:59 -0700 (PDT)

Hello,

I have a problem to flip a 200x200 matrix, which is imported by a .asc file. I want to flip the matrix like in a created example below:

> b <- matrix(1:9,3,3,byrow=T)
> b

     [,1] [,2] [,3]

[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9

> b1 <- apply(t(b),1,rev)

> b1

     [,1] [,2] [,3]

[1,]    7    8    9
[2,]    4    5    6
[3,]    1    2    3

but my R Script doesn't work so. I don't know where the problem is. What's the different between a created matrix and a imported matrix?

Here is my r Script:

a <- read.table("c:/Test/Test.asc", header=FALSE, sep=" ") dim(a)
b <- matrix(a, nrow=200, byrow=TRUE)
d <- apply(t(b),1,rev)

write.table(d, file = "c:/Test/output.asc", sep = " ", row.names = FALSE, col.names = FALSE)

My output ist like this

input:

1 2 3
4 5 6
7 8 9

output:

3 2 1
6 5 4
9 8 7

but it should be like this, as in the example:

7 8 9
4 5 6
1 2 3

thanks.

-- 
View this message in context: http://www.nabble.com/Flip-Matrix-form-file--tp18614800p18614800.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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 23 Jul 2008 - 17:31:08 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 23 Jul 2008 - 18:32:19 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