[R] how to rotate elements in a vector and points in a plane

David Winsemius dwinsemius at comcast.net
Fri Apr 23 20:28:14 CEST 2010


On Apr 23, 2010, at 1:54 PM, Ondřej Mikula wrote:

> Dear R-helpers,
>
> I need two simple functions, I guess they exist in R, but I am unable
> to find them.
> The first function should cyclically rotate elements in a vector.
> ("guyrot" in the package "wavethresh" should do it, but there's some
> problem with its loading)

 > rot <- function(x) (1:x %% x) +1
 > rot(9)
[1] 2 3 4 5 6 7 8 9 1
 > rotvec <- function(vec) vec[rot(length(vec))]

 > rotvec(c(3,4,5,6,7))
[1] 4 5 6 7 3

> The second function should rotate points in 2D by a given angle (about
> the defined point).

That's all the homework I choose to do today.

>
> Thanks for any advice
> Ondra Mikula
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list