[Seqinr-commits] r1623 - pkg/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jul 17 23:46:40 CEST 2009
Author: lobry
Date: 2009-07-17 23:46:40 +0200 (Fri, 17 Jul 2009)
New Revision: 1623
Added:
pkg/man/swap.Rd
Log:
new function
Added: pkg/man/swap.Rd
===================================================================
--- pkg/man/swap.Rd (rev 0)
+++ pkg/man/swap.Rd 2009-07-17 21:46:40 UTC (rev 1623)
@@ -0,0 +1,54 @@
+\name{swap}
+\alias{swap}
+\title{Exchange two R objects}
+\description{
+Exchange object \code{x} with object \code{y}.
+}
+\usage{
+swap(x, y)
+}
+\arguments{
+ \item{x}{an R object}
+ \item{y}{an R object}
+}
+\value{
+none.
+}
+\references{
+\code{citation("seqinr")}
+}
+\author{ J.R. Lobry }
+\seealso{\code{\link{move}} }
+
+\examples{
+#
+# Example in a new empty environment:
+#
+local({
+ x <- 0:9
+ y <- 10:19
+ print(x)
+ print(y)
+ swap(x[1], y[2])
+ print(x)
+ print(y)
+})
+#
+# Sanity check with a bubble sort:
+#
+bubble.sort <- function(tab, n = length(tab)){
+ i <- 1
+ while(i < n){
+ if(tab[i + 1] < tab[i]){
+ swap(tab[i], tab[i+1])
+ i <- 1
+ } else {
+ i <- i+1
+ }
+ }
+ return(tab)
+}
+set.seed(1)
+x <- rnorm(10)
+stopifnot(identical(sort(x), bubble.sort(x)))
+}
More information about the Seqinr-commits
mailing list