Re: [R] identify selected substances across individuals

From: Peter Alspach <>
Date: Sun 21 Jan 2007 - 20:58:27 GMT


> Below is an example data, which contains three id-numbers.
> For each id there are three substances in each of the three
> blocks. Some substances are repeated twice.The subsatances
> are the same for all ids. The id number 3 is actually a
> control so all responses (y) that are equal or greater than 4
> are supposed to be removed from this id number. This I can do
> easily in R but what I need help with is I want to have those
> substances that are removed from id number 3 also removed
> from other ids as well. I could do an algorithm like : for id
> in 1:2, if substance = c("abc","dgf") then delete but if the
> substances to be removed have long strings and are more than
> 2 (for example 20 substances) then it would take long time to
> list the substances manually. Can you guys please show me a
> clever way to do what I described above ?

Use subsetting to identify that substances, and then !(...%in%...) to remove records with these substances:

yourData[!(yourData$substance %in% yourData[yourData$id==3 & yourData$y>=4, 'substance']),]

The above is untested and will need modification is yourData$id or yourData$y contains missing values.    

Peter Alspach

The contents of this e-mail are privileged and/or confidenti...{{dropped}} mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon Jan 22 08:02:53 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 21 Jan 2007 - 22:30:33 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.