library(SpatialKWD)
# Define a simple histogram
h <- new(Histogram2D)
# Add half unit of mass at positions (1,0) and (0,1)
h$add(1, 0, 0.5)
h$add(0, 1, 0.5)
# Add at position (5,5) a unit of mass
h$add(5, 5, 1)
# Normalize the histogram
h$normalize()
# Print the total weight (mass) of the histogram
print(sprintf("Histogram total weight = %f", h$balance()))
Run the code above in your browser using DataLab