3D Binning

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

3D Binning

vioravis
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.
 

Reply | Threaded
Open this post in threaded view
|

Re: 3D Binning

Petr Savicky-2
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.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Binning

vioravis
This worked fine. Thanks.