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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 18 11:34:59 CEST 2014


Author: mvkorpel
Date: 2014-04-18 11:34:59 +0200 (Fri, 18 Apr 2014)
New Revision: 822

Modified:
   pkg/dplR/ChangeLog
   pkg/dplR/DESCRIPTION
   pkg/dplR/R/ccf.series.rwl.R
   pkg/dplR/man/ccf.series.rwl.Rd
Log:
ccf.series.rwl(): 'series' can be a series name or index


Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog	2014-04-18 04:34:37 UTC (rev 821)
+++ pkg/dplR/ChangeLog	2014-04-18 09:34:59 UTC (rev 822)
@@ -25,6 +25,9 @@
 - Switched the order of x and y in the call to ccf(). This makes a great deal
   more logical sense now as a missing ring shows up with a positive lag rather
   than a negative lag.
+- New convenience feature: if the length of 'series' is 1, it is
+  interpreted as a column index to 'rwl', and the corresponding
+  series is left out of the master chronology.
 
 File: ffcsaps.R
 ---------------

Modified: pkg/dplR/DESCRIPTION
===================================================================
--- pkg/dplR/DESCRIPTION	2014-04-18 04:34:37 UTC (rev 821)
+++ pkg/dplR/DESCRIPTION	2014-04-18 09:34:59 UTC (rev 822)
@@ -3,7 +3,7 @@
 Type: Package
 Title: Dendrochronology Program Library in R
 Version: 1.6.0
-Date: 2014-04-16
+Date: 2014-04-18
 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph",
         "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko",
         "Korpela", role = c("aut", "trl")), person("Franco", "Biondi",

Modified: pkg/dplR/R/ccf.series.rwl.R
===================================================================
--- pkg/dplR/R/ccf.series.rwl.R	2014-04-18 04:34:37 UTC (rev 821)
+++ pkg/dplR/R/ccf.series.rwl.R	2014-04-18 09:34:59 UTC (rev 822)
@@ -12,10 +12,35 @@
     }
     seg.lag <- seg.length / 2
 
+    ## Handle different types of 'series'
+    if (length(series) == 1) {
+        if (is.character(series)) {
+            seriesIdx <- logical(ncol(rwl))
+            seriesIdx[colnames(rwl) == series] <- TRUE
+            nMatch <- sum(seriesIdx)
+            if (nMatch == 0) {
+                stop("'series' not found in 'rwl'")
+            } else if (nMatch != 1) {
+                stop("duplicate column names, multiple matches")
+            }
+            rwl2 <- rwl[, !seriesIdx, drop = FALSE]
+            series2 <- rwl[, seriesIdx]
+            names(series2) <- rownames(rwl)
+        } else if (is.numeric(series) && is.finite(series) &&
+                   series >=1 && series < ncol(rwl) + 1) {
+            rwl2 <- rwl[, -series, drop = FALSE]
+            series2 <- rwl[, series]
+            names(series2) <- rownames(rwl)
+        } else {
+            stop("'series' of length 1 must be a column index to 'rwl'")
+        }
+    } else {
+        rwl2 <- rwl
+        series2 <- series
+        names(series2) <- series.yrs
+    }
     ## Normalize.
-    series2 <- series
-    names(series2) <- series.yrs
-    tmp <- normalize.xdate(rwl, series2, n, prewhiten, biweight)
+    tmp <- normalize.xdate(rwl2, series2, n, prewhiten, biweight)
     master <- tmp$master
 
     ## trim master so there are no NaN like dividing when only one
@@ -76,7 +101,7 @@
             bin.ccf <- NA
         }
         else {
-            tmp <- ccf(series2[mask], master[mask], lag.max=lag.max, 
+            tmp <- ccf(series2[mask], master[mask], lag.max=lag.max,
                        plot=FALSE)
             bin.ccf <- as.vector(tmp$acf)
         }

Modified: pkg/dplR/man/ccf.series.rwl.Rd
===================================================================
--- pkg/dplR/man/ccf.series.rwl.Rd	2014-04-18 04:34:37 UTC (rev 821)
+++ pkg/dplR/man/ccf.series.rwl.Rd	2014-04-18 09:34:59 UTC (rev 822)
@@ -15,10 +15,15 @@
 \arguments{
   \item{rwl}{ a \code{data.frame} with series as columns and years as rows
     such as that produced by \code{\link{read.rwl}}. }
-  \item{series}{ a \code{numeric} vector. Usually a tree-ring series. }
+  \item{series}{ a \code{numeric} or \code{character} vector.  Usually a
+    tree-ring series.  If the length of the value is 1, the
+    corresponding column of \code{\var{rwl}} is selected (by name or
+    position) as the series and ignored when building the master
+    chronology.  Otherwise, the value must be \code{numeric}. }
   \item{series.yrs}{ a \code{numeric} vector giving the years of
     \code{\var{series}}.  Defaults to
-    \code{as.numeric(names(\var{series}))}. }
+    \code{as.numeric(names(\var{series}))}.  Ignored if
+    \code{\var{series}} is an index to a column of \code{\var{rwl}}. }
   \item{seg.length}{ an even integral value giving length of segments in
     years (e.g., 20, 50, 100 years). }
   \item{bin.floor}{ a non-negative integral value giving the base for
@@ -103,5 +108,13 @@
 names(flagged) <- rownames(dat)
 dat$"641143" <- NULL
 ccf.100 <- ccf.series.rwl(rwl = dat, series = flagged, seg.length = 100)
+\dontrun{
+## Select series by name or column position
+ccf.100.2 <- ccf.series.rwl(rwl = co021, seg.length = 100,
+                            series = "641143")
+ccf.100.3 <- ccf.series.rwl(rwl = co021, seg.length = 100,
+                            series = which(colnames(co021) == "641143"))
+identical(ccf.100.2, ccf.100.3)
 }
+}
 \keyword{ manip }



More information about the Dplr-commits mailing list