[R] identify selected substances across individuals
Peter Alspach
PAlspach at hortresearch.co.nz
Sun Jan 21 21:58:27 CET 2007
Jenny
> 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}}
More information about the R-help
mailing list