[adegenet-commits] r262 - in pkg: R data man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 28 12:48:19 CET 2009


Author: jombart
Date: 2009-01-28 12:48:18 +0100 (Wed, 28 Jan 2009)
New Revision: 262

Modified:
   pkg/R/genind2genpop.R
   pkg/data/sim2pop.RData
   pkg/man/genind2genpop.Rd
Log:
Fixed genind2genpop doc (example)


Modified: pkg/R/genind2genpop.R
===================================================================
--- pkg/R/genind2genpop.R	2009-01-28 11:12:52 UTC (rev 261)
+++ pkg/R/genind2genpop.R	2009-01-28 11:48:18 UTC (rev 262)
@@ -67,16 +67,18 @@
   if(proceed.other){
       ## auxiliary function doing the job
       fOther <- function(e){
-          N <- row(x at tab)
-          if(is.vector(e) & is.numeric(e) & length(e)==N){ # numeric vector
+          N <- nrow(x at tab)
+          if(is.vector(e) && is.numeric(e) && length(e)==N){ # numeric vector
               res <- tapply(e, pop, other.action)
               return(res)
-          } else if(is.matrix(e) & is.numeric(e) & nrow(e)==N){ # numeric matrix
+          } else if(is.matrix(e) && is.numeric(e) && nrow(e)==N){ # numeric matrix
               res <- apply(e, 2, function(vec) tapply(vec, pop, other.action))
+              colnames(res) <- colnames(e)
               return(res)
-          } else if(is.data.frame(e) & nrow(e)==N & all(sapply(e,is.numeric)) ){ # df of numeric vectors
+          } else if(is.data.frame(e) && nrow(e)==N && all(sapply(e,is.numeric)) ){ # df of numeric vectors
               res <- lapply(e, function(vec) tapply(vec, pop, other.action))
               res <- data.frame(res)
+              names(res) <- names(e)
               return(res)
           } else return(e)
       } # end fOther

Modified: pkg/data/sim2pop.RData
===================================================================
(Binary files differ)

Modified: pkg/man/genind2genpop.Rd
===================================================================
--- pkg/man/genind2genpop.Rd	2009-01-28 11:12:52 UTC (rev 261)
+++ pkg/man/genind2genpop.Rd	2009-01-28 11:48:18 UTC (rev 262)
@@ -55,11 +55,30 @@
   \linkS4class{genind}, \linkS4class{genpop}, \code{\link{na.replace}}
 }
 \examples{
+## simple conversion
   data(nancycats)
   nancycats
   catpop <- genind2genpop(nancycats)
   catpop
   summary(catpop)
+
+## proceeding the @other slot
+data(sim2pop)
+sim2pop$other$foo <- letters
+sim2pop
+dim(sim2pop$other$xy) # matches the number of genotypes
+sim2pop$other$foo # does not match the number of genotypes
+
+obj <- genind2genpop(sim2pop, proceed.other=TRUE)
+obj$other # the new xy is the populations' centre
+
+pch <- as.numeric(pop(sim2pop))
+col <- pop(sim2pop)
+levels(col) <- c("blue","red")
+col <- as.character(col)
+plot(sim2pop$other$xy, pch=pch, col=col)
+text(obj$other$xy, lab=row.names(obj$other$xy), col=c("blue","red"), cex=2, font=2)
+
 }
 \keyword{classes}
 \keyword{manip}



More information about the adegenet-commits mailing list