[R] Flip Matrix form file?

Chris82 rubenbauar at gmx.de
Wed Jul 23 18:23:59 CEST 2008


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.



More information about the R-help mailing list