Skip to content
Prev 247860 / 398503 Next

subsets

On 2011-01-20 02:05, Taras Zakharko wrote:
Here's a tidy version using the plyr package:

require(plyr)
df1 <- ddply(df, .(id), summarize,
      has.both = ("ah" %in% diagnosis) & ("ihd" %in% diagnosis),
      has.only.ah = ("ah" %in% diagnosis) & !("ihd" %in% diagnosis),
      has.only.ihd = !("ah" %in% diagnosis) & ("ihd" %in% diagnosis)
)

Further processing on the columns of df1 is straightforward.

Peter Ehlers