[R] Flipping a vector
Marc Schwartz
marc_schwartz at comcast.net
Sun Mar 18 03:58:35 CET 2007
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
More information about the R-help
mailing list