[R] arithmetic problem

Iain Gallagher iaingallagher at btopenworld.com
Sat May 30 16:13:01 CEST 2009


Hello list

I have a problem with a dataset (see toy example below) where I am trying to find the difference between two (or more numbers) and discard those observations which fall outside a set interval.

An example and further explanation:

   values      ind
1    2655      7A5
2    3028      7A5
3     689   ABBA-1
4    1336   ABBA-1
5    1560   ABBA-1
6    2820   ABLIM1
7    3339   ABLIM1
8     171    ACSM5
9     195    ACSM5
10     43 ADAMDEC1
11    129 ADAMDEC1
12   1105     AFF1
13   3202     AFF1
14    852     AFF3
15   2461     AFF3
16     45     AKT1
17    397     AKT1
18   1430     AQP2
19   2402     AQP2
20   2551 ARHGAP19

Each number in the values column above is associated with a label (in the ind column). For some inds there will be only 2 values but as can be seen from the data other inds have many values.

Here's what I want to do using the ABBA-1 data from above as an example:

calculate the differences between each value:

1560-1336 = 224
1336-689 = 647

then use these values to create an index that will allow me to pull out values between set limits. If I set the limits to between 200 and 300 then the index will reference rows 4 & 5 in the above data set.

I hope this is reasonably clear and I appreciate any suggestions.

Thanks

Iain





More information about the R-help mailing list