Commits

Stefano Costa committed b7d20a0

Move the routine to a proper R function object

Comments (0)

Files changed (2)

mpi.R

-# mpi.R
-# medie ponderate individuali
-
-ends <- parker5th$EndDate
-starts <- parker5th$StartDate
-lunghezzaparker <- length(parker5th$Lat)
-passo <- 10
-
-endt <- max(starts) - passo/2
-startt <- min(ends) + passo/2
-
-sequenza <- seq(startt,endt,by=passo)
-
-anni <- data.frame(anno=sequenza, valore=seq(0,0,length=length(sequenza)))
-lunghezzaanni <- length(anni$anno)
-
-for ( i in 1:lunghezzaanni )
-        for ( j in 1:lunghezzaparker )
-                if ( anni$anno[i] < ends[j] && anni$anno[i] > starts[j] )
-                        anni$valore[i] <- anni$valore[i] + passo/(ends[j] - starts[j])
+# mpi.r
+#
+# MPI = medie ponderate individuali
+#
+# An R implementation of a weighting method for doing summary
+# statistics of archaeological data.
+#
+# 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
+  parker.length <- length(quantities)
+  sequence <- seq(start.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])
+  years
+}