Skip to content
Back to formatted view

Raw Message

Message-ID: <AANLkTi=GCbfgRhOGNPLOXCTDtKAC+GL1Cg2xfyqLHmy+@mail.gmail.com>
Date: 2011-01-31T21:43:24Z
From: Rajarshi Guha
Subject: identify subsets based on two grouping factors

Hi, I have a data.frame that has a categorical variable, for which I
would like to look at the distribution of levels of this variable,
based on a grouping of two other variables.

As an example:

x <- data.frame(obs=sample(c('low', 'high'),100, replace=TRUE),
grp1=sample(1:10, 100, replace=TRUE),
grp2=runif(100))

cut.grp1 <- cut(x$grp1, 3)
cut.grp2 <- cut(x$grp2, 3)

Thus, for each combination of levels in cut.grp1 and cut.grp2, I'd
like to obtain the distribution of levels obs. I know I can loop over
each pair of levels in cut.grp1 and cut.grp2, but is there a more
elegant way to achieve this?

-- 
Rajarshi Guha
NIH Chemical Genomics Center