Hi Trying to work out that: Each person can take from 1 to 9 drugs. And data frame looks like id drug 1 d 2 g 2 d 2 r 3 e 3 a ........... Q: How many drugs one person takes on average? Thank you
Homework exercise ?? -- Bert On Tue, Jan 18, 2011 at 2:03 PM, Denis Kazakiewicz <d.kazakiewicz at gmail.com> wrote:> > Hi > > Trying to work out that: > Each person can take from 1 to 9 drugs. And data frame looks like > > > id ? ? ?drug > 1 ? ? ? d > 2 ? ? ? g > 2 ? ? ? d > 2 ? ? ? r > 3 ? ? ? e > 3 ? ? ? a > ........... > > Q: How many drugs one person takes on average? > > Thank you > > ______________________________________________ > R-help at r-project.org 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. >-- Bert Gunter Genentech Nonclinical Biostatistics
On Jan 18, 2011, at 5:03 PM, Denis Kazakiewicz wrote:> > Hi > > Trying to work out that: > Each person can take from 1 to 9 drugs. And data frame looks like > > > id drug > 1 d > 2 g > 2 d > 2 r > 3 e > 3 a > ........... > > Q: How many drugs one person takes on average?Something like: mean( with(dfrm, tapply(drug, id, length), na,rm=TRUE) ) ) (Not sure if the na.rm is needed , but it cannot hurt)>-- David Winsemius, MD West Hartford, CT