[R] Turn any vector

jim holtman jholtman at gmail.com
Thu Jul 10 14:05:25 CEST 2008


Is this what you want:

> x <- 1:10
> x
 [1]  1  2  3  4  5  6  7  8  9 10
> rev(x)
 [1] 10  9  8  7  6  5  4  3  2  1
>


On Thu, Jul 10, 2008 at 7:56 AM, Zroutik Zroutik <zroutik at gmail.com> wrote:
> Dear R-users,
>
> I'd like to turn a vector so it starts with it's end. For better
> understanding, this set of commands will do what I need:
>
> i <- seq(1:10)
> i_turned <- i
> for (j in 1:length(i)) i_turned[j] <- i[length(i)-j+1]
>
> now, i_turned is what I call turned. Is there a function which would make a
> script lighter? Thank you upfront for any hint.
>
> Best regards,
> Zroutik
>
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list