[R] How to remove rows based on frequency of factor and then difference date scores

Chris Beeley chris.beeley at gmail.com
Tue Aug 24 19:19:47 CEST 2010


Hello-

A basic question which has nonetheless floored me entirely. I have a
dataset which looks like this:

Type  ID     Date            Value
A       1    16/09/2020       8
A       1     23/09/2010      9
B       3     18/8/2010        7
B       1     13/5/2010        6

There are two Types, which correspond to different individuals in
different conditions, and loads of ID labels (1:50) corresponding to
the different individuals in each condition, and measurements at
different times (from 1 to 10 measurements) for each individual.

I want to perform the following operations:

1) Delete all individuals for whom only one measurement is available.
In the dataset above, you can see that I want to delete the row Type B
ID 3, and Type B ID 1, but without deleting the Type A ID 1 data
because there is more than one measurement for Type A ID 1 (but not
for Type B ID1)

2) Produce difference scores for each of the Dates, so each individual
(Type A ID1 and all the others for whom more than one measurement
exists) starts at Date "1" and goes up in integers according to how
many days have elapsed.

I just know there's some incredibly cunning R-ish way of doing this
but after many hours of fiddling I have had to admit defeat.

I would be very grateful for any words of advice.

Many thanks,
Chris Beeley,
Institute of Mental Health, UK



More information about the R-help mailing list