Problem description: I have a list of $\{x,y\}$ pairs. I'd like to divide $x$ into equal[*] bins, say $bx_1, bx_2, \ldots$, calculate $\leftListPlot[]
.
Question: I've already done it manually, but I was wondering whether:
- exists a builtin function in Mathematica that does what I want.
- exists a builtin function that I could use in my own implementation (e.g.,
HistogramList[]
?).
[*] Bins with the same interval. Equally spaced intervals.
EDIT: Largely off-topic, but in R
it turns out to be very easy with the fields
package:
library('fields')
df <- read.table('my.dat') # V1 -> off-axis distance, V2 -> energy
st <- stats.bin(x=df$V1, y=df$V2, N=100)
df2 <- as.data.frame(st$stats["mean",])
# Plot mean energy for every distance bin
# EDIT: Actually I should plot against `centers` of `st`, but anyway.
names(df2) <- c('mean.energy')
plot(df2$mean.energy, type="s",
xlab="Off-axis distance (mm)", ylab="Mean Energy (MeV)")
Comments
Post a Comment