Commits

Stefano Costa committed 821beab

Allow for arbitrary date ranges.

Useful for combining multiple, non entirely overlapping curves.

Comments (0)

Files changed (1)

 #
 # Copyright 2011 Stefano Costa
 
-mpi <- function(quantities, start.date, end.date, step) {
-  start.step <- min(start.date) - step / 2
-  end.step <- max(end.date) + step / 2
+mpi <- function(quantities, begin.dates, end.dates, step=5, start.year=NULL, stop.year=NULL) {
+  if (is.null(start.year))
+    begin.step <- min(begin.dates) - step / 2
+  else
+    begin.step <- start.year - step / 2
+  if (is.null(stop.year))
+    end.step <- max(end.dates) + step / 2
+  else
+    end.step <- stop.year - step / 2
   parker.length <- length(quantities)
-  sequence <- seq(start.step, end.step, by=step)
+  sequence <- seq(begin.step, end.step, by=step)
   years <- data.frame(year=sequence, value=seq(0,0,length=length(sequence)))
   for ( i in 1:length(years$year) )
     for ( j in 1:parker.length )
-      if ( years$year[i] < end.date[j] && years$year[i] > start.date[j] )
-        years$value[i] <- years$value[i] + step * quantities[j] / (end.date[j] - start.date[j])
+      if ( years$year[i] < end.dates[j] && years$year[i] > begin.dates[j] )
+        years$value[i] <- years$value[i] + step * quantities[j] / (end.dates[j] - begin.dates[j])
   years
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.