I did try it. It gave me [[1]] id diagnosis 1 1 ah 5 3 ah 7 4 ah 8 4 ihd 10 5 ihd
[[2]] id diagnosis 1 1 ah 2 2 ah 5 3 ah 7 4 ah [[3]] id diagnosis 3 2 ihd 8 4 ihd 10 5 ihd Which isn't what the OP asked for > Q: How to make three data sets: > 1. Patients with ah and ihd id diagnosis 2 2 ah 3 2 ihd 4 2 im 7 4 ah 8 4 ihd 9 4 angina > 2. Patients with ah but no ihd id diagnosis 1 1 ah 5 3 ah 6 3 stroke > 3. Patients with ihd but no ah? id diagnosis 10 5 ihd Regards, KJ --------------------------------- "Henrique Dallazuanna" <www...@gmail.com> wrote in message news:aanlktikqnw_hntdyxdrj+ytyqf6tghlmh0qsleouf...@mail.gmail.com... Try this: lapply(list(c('ah', 'ihd'), 'ah', 'ihd'), function(x)subset(aDF, diagnosis == x)) On Thu, Jan 20, 2011 at 6:53 AM, Den <d.kazakiew...@gmail.com> wrote: > Dear R people > Could you please help. > > Basically, there are two variables in my data set. Each patient ('id') > may have one or more diseases ('diagnosis'). It looks like > > id diagnosis > 1 ah > 2 ah > 2 ihd > 2 im > 3 ah > 3 stroke > 4 ah > 4 ihd > 4 angina > 5 ihd > .............. > Q: How to make three data sets: > 1. Patients with ah and ihd > 2. Patients with ah but no ihd > 3. Patients with ihd but no ah? > > If you have any ideas could just guide what should I look for. Is a > subset or aggregate, or loops, or something else??? I am a bit lost. (F1 > F1 F1 !!!:) > Thank you > > ______________________________________________ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] -------------------------------------------------------------------------------- > ______________________________________________ R-help@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.