Ondřej Mikula
2010-Apr-23 17:54 UTC
[R] how to rotate elements in a vector and points in a plane
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) The second function should rotate points in 2D by a given angle (about the defined point). Thanks for any advice Ondra Mikula
David Winsemius
2010-Apr-23 18:28 UTC
[R] how to rotate elements in a vector and points in a plane
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