Re: [R] mirror vector?

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Fri 28 Jul 2006 - 18:00:09 EST

Hi Antje

use the fact that n:1 counts backwards from n, and then use this as a row index:

 > m <- matrix(1:30,5,6)
 > m[nrow(m):1,]

      [,1] [,2] [,3] [,4] [,5] [,6]

[1,]    5   10   15   20   25   30
[2,]    4    9   14   19   24   29
[3,]    3    8   13   18   23   28
[4,]    2    7   12   17   22   27
[5,]    1    6   11   16   21   26


[
a more general answer would be

library(magic)
arev(m,1)
]

HTH rksh

On 28 Jul 2006, at 08:50, <niederlein-rstat@yahoo.de> wrote:

> Hello,
>
> I'm an absolut beginner with R and now I got a 2D vector with
> numbers. I would like to mirror this vector now by the rows (so
> that the first row becomes last, second becomes one before last, ...).
> I don't know if there is any method I can use to do this.
> Could you please help me?
>
> Antje
>
>
> ---------------------------------
> Was Sie schon immer wissen wollten aber nie zu Fragen trauten?
> Yahoo! Clever hilft Ihnen.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
R-help@stat.math.ethz.ch 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 Fri Jul 28 18:32:04 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 28 Jul 2006 - 20:19:12 EST.

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