[Dplr-commits] r990 - in pkg/dplR: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 1 22:20:43 CEST 2015


Author: andybunn
Date: 2015-06-01 22:20:42 +0200 (Mon, 01 Jun 2015)
New Revision: 990

Added:
   pkg/dplR/R/treeMean.R
   pkg/dplR/man/treeMean.Rd
Modified:
   pkg/dplR/ChangeLog
   pkg/dplR/NAMESPACE
Log:
New function to calculate the mean value for a single tree across multiple cores. Still needs error checking and some more work on the help page.

Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog	2015-06-01 11:51:23 UTC (rev 989)
+++ pkg/dplR/ChangeLog	2015-06-01 20:20:42 UTC (rev 990)
@@ -1,7 +1,10 @@
 * CHANGES IN dplR VERSION 1.6.4
 
+File: treeMean.R
+-------------
+- Made a new function to calculate the mean value of each tree when there are 
+  multiple cores.
 
-
 * CHANGES IN dplR VERSION 1.6.3
 
 File: crn.plot.R
@@ -36,10 +39,10 @@
   requirement (>= 0.5-2) was a mistake.
 - Updated version requirement: R (>= 2.15.2).  For some reason, R
   CMD check does not play nice with testthat on earlier versions of R.
-- Removed one of the URLs in the URL field. BDR sent an email saying that
+- Removed one of the URLs in the URL field. BDR sent and email saying that 
   having two URLs was breaking R and that we should put a comma in betwixt
   them. But the comma is problematic as it is a valid part of some URLs.
-  We decided the better part of valor was to keep only one URL and not fight
+  We deicded the better part of valor was to keep only one URL and not fight
   this particular battle.
 
 File: NAMESPACE

Modified: pkg/dplR/NAMESPACE
===================================================================
--- pkg/dplR/NAMESPACE	2015-06-01 11:51:23 UTC (rev 989)
+++ pkg/dplR/NAMESPACE	2015-06-01 20:20:42 UTC (rev 990)
@@ -52,7 +52,7 @@
        write.compact, write.crn, write.rwl, write.tridas,
        write.tucson, plot.rwl, interseries.cor, summary.rwl,
        plot.crn, insert.ring, delete.ring, xskel.ccf.plot, xskel.plot,
-       latexify, latexDate, rasterPlot)
+       latexify, latexDate, rasterPlot, treeMean)
 
 S3method(print, redfit)
 S3method(plot, rwl)

Added: pkg/dplR/R/treeMean.R
===================================================================
--- pkg/dplR/R/treeMean.R	                        (rev 0)
+++ pkg/dplR/R/treeMean.R	2015-06-01 20:20:42 UTC (rev 990)
@@ -0,0 +1,14 @@
+treeMean <- function(rwl,ids){
+  rwl2 <- as.matrix(rwl)
+  trees <- ids$tree
+  uTrees <- unique(trees)
+  res <- matrix(NA, nrow=nrow(rwl2), ncol=length(uTrees))
+  for (i in seq(along=uTrees)) {
+    res[,i] <- rowMeans(rwl2[,trees == uTrees[i], drop=FALSE], na.rm=TRUE)
+  }
+  res[is.nan(res)] <- NA
+  res <- as.data.frame(res)
+  colnames(res) <- uTrees
+  rownames(res) <- rownames(rwl)
+  res
+}

Added: pkg/dplR/man/treeMean.Rd
===================================================================
--- pkg/dplR/man/treeMean.Rd	                        (rev 0)
+++ pkg/dplR/man/treeMean.Rd	2015-06-01 20:20:42 UTC (rev 990)
@@ -0,0 +1,50 @@
+\encoding{UTF-8}
+\name{treeMean}
+\alias{treeMean}
+\title{Calculate mean across cores in a tree}
+\description{
+  This function calculates the mean value for each tree in a rwl or rwi object.
+}
+\usage{
+treeMean(rwl, ids)
+}
+\arguments{
+  \item{x}{a \code{data.frame} of ring widths with
+    \code{rownames(\var{x})} containing years and \code{colnames(x)}
+    containing each series \acronym{ID} such as produced by
+    \code{\link{read.rwl}}}
+  \item{ids}{ an optional \code{data.frame} with column one named
+    \code{"tree"} giving a \code{numeric} \acronym{ID} for each tree and
+    column two named \code{"core"} giving a \code{numeric} \acronym{ID}
+    for each core.  Defaults to one core per tree as\cr
+    \code{data.frame(tree=1:ncol(\var{rwi}), core=rep(1, ncol(\var{rwi})))}. }
+}
+\details{
+  Here.
+}
+\value{
+  A \code{data.frame} with the means of each tree.
+}
+
+\author{ Andy Bunn.  Patched and improved by Mikko Korpela. }
+
+\seealso{ \code{\link{read.rwl}}, \code{\link{read.ids}}
+}
+\examples{
+data(gp.rwl)
+gp.ids <- read.ids(gp.rwl, stc = c(0, 2, 1))
+gp.treeMean <- treeMean(gp.rwl,gp.ids)
+
+data(ca533)
+ca533.treeMean <-treeMean(ca533,autoread.ids(ca533))
+# look at an example of two cores per tree
+tail(ca533[,c("CAM031","CAM032"),drop=FALSE])
+tail(rowMeans(ca533[,c("CAM031","CAM032"),drop=FALSE],na.rm=TRUE))
+tail(ca533.treeMean[,"3",drop=FALSE])
+# look at an example of single tree
+ca533[,"CAM011",drop=FALSE]
+ca533.treeMean[,1]
+ca533[905,"CAM011"]
+ca533.treeMean[905,1]
+}
+\keyword{ manip }



More information about the Dplr-commits mailing list