## load library
library("MALDIquant");
## create two MassPeaks objects
p <- list(createMassPeaks(mass=seq(100, 500, 100),
intensity=1:5),
createMassPeaks(mass=c(seq(100.2, 300.2, 100), 395),
intensity=1:4));
## only keep peaks which occur in all MassPeaks objects
binnedPeaks <- binPeaks(p, tolerance=0.002);
## compare result
iM1 <- intensityMatrix(p);
iM2 <- intensityMatrix(binnedPeaks);
all(dim(iM1) == c(2, 9)); # TRUE
all(dim(iM2) == c(2, 6)); # TRUE
show(iM2);
## increase tolerance
binnedPeaks <- binPeaks(p, tolerance=0.1);
iM3 <- intensityMatrix(binnedPeaks);
all(dim(iM3) == c(2, 5)); # TRUE
show(iM3);Run the code above in your browser using DataLab