[R] 3D Binning

Petr Savicky savicky at praha1.ff.cuni.cz
Tue Jan 25 22:07:47 CET 2011


On Tue, Jan 25, 2011 at 06:00:36AM -0800, vioravis wrote:
> 
> I am trying to do binning on three variables (3d binning). The bin boundaries
> are specified by the user separately for each variable. I used the bin2
> function in the 'ash' package for 2d binning that involves only two
> variables but didn't any package for similar binning with three variables.
> Are there any packages or codes available for 3d binning?? Thank you. 

Try the following, possibly with different breaks for each dimension.

  x <- matrix(rnorm(30000), ncol=3)
  breaks <- seq(-1, 1, length=5)
  xints <- data.frame(
  x1=cut(x[, 1], breaks=breaks),
  x2=cut(x[, 2], breaks=breaks),
  x3=cut(x[, 3], breaks=breaks))
  table(complete.cases(xints))
  xtabs(~ ., xints)

Hope this helps.

Petr Savicky.



More information about the R-help mailing list