[R] Flipping a vector

Marc Schwartz
Sun, 18 Mar 2007 02:58:35 -0000

On Sun, 2007-03-18 at 02:52 +0000, adschai at optonline.net
wrote:
> Hi all - A stupid question here, my apology. I would like to know how can I
flip a vector in R? For example, I have a vector:
>
> a = c(1,2,3)
>
> I would like my vector b to have the following value
>
> b = c(1,2,3)

I presume you meant:

b <- c(3, 2, 1)

?

> But what operator I need to put to my original vector 'a' to obtain
'b'? Please let me know. Thank you.

See ?rev

a <- c(1, 2, 3)

b <- rev(a)

> b
[1] 3 2 1


HTH,

Marc Schwartz