[R] reverse vector elements
Chuck Cleland
ccleland at optonline.net
Tue Feb 12 13:51:02 CET 2008
On 2/12/2008 7:47 AM, mohamed nur anisah wrote:
> Dear lists,
>
> I want to write a function of a vector and reverse the order of its elements. Here is my code:
>
> revector<-function(n){
> y=vector(length=n)
> for(i in n:1){
> y[i]=i
> }
> return(y)
> }
>
> i want my output to be like this:
> y
> [1] 10 9 8 7 6 5 4 3 2 1
>
> Any suggestion?? Thanks!!
> Cheers,
> Anisah
?rev
rev(1:10)
[1] 10 9 8 7 6 5 4 3 2 1
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list