s-news
[Top] [All Lists]

Reducing a data set

To: s-news@lists.biostat.wustl.edu
Subject: Reducing a data set
From: Eric yang <yang_eric9@yahoo.com>
Date: Tue, 19 Sep 2006 14:49:58 -0700 (PDT)
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=4Mo2jZJcIeRuwnh/Kg6FMDa+tSPhPfV1V4n+1NA6YiMp6IaTJlWT7t0BQBYHlKLT+Yw6/U3VfHxylOZry1KIbT/BcpCh7BMVJD32Xr/JU5Yxh2Fgi+FZdHVpMSDkRr2h620RpXknY16k0/UbxpLrHmOHYJKR/4dKOvUpvjQPR4A= ;
 
Dear all,
 
I would like to know a fast way of reducing a data set based on certain conditions. For example, suppose I have the following data set
 
my.data <- data.frame(ID=c(rep("101-1", 10), rep("102-12", 14), rep("103-10", 3), rep("104-2", 8)), score=round(100*runif(35)))
 
> my.data
ID score
1 101-1 85
2 101-1 32
3 101-1 22
4 101-1 74
5 101-1 48
6 101-1 47
7 101-1 46
8 101-1 6
9 101-1 58
10 101-1 37
11 102-12 16
12 102-12 78
13 102-12 15
14 102-12 45
15 102-12 99
16 102-12 4
17 102-12 99
18 102-12 35
19 102-12 78
20 102-12 16
21 102-12 91
22 102-12 34
23 102-12 10
24 102-12 20
25 103-10 43
26 103-10 12
27 103-10 57
28 104-2 86
29 104-2 45
30 104-2 85
31 104-2 81
32 104-2 9
33 104-2 40
34 104-2 47
35 104-2 74
I would like to reduce the data set such that I have at most the top 5 scores for each ID number. Thus, I would end up with the following data set:
1 101-1 85
4 101-1 74
5 101-1 48
6 101-1 47
9 101-1 58
12 102-12 78
15 102-12 99
17 102-12 99
19 102-12 78
21 102-12 91
25 103-10 43
26 103-10 12
27 103-10 57
28 104-2 86
30 104-2 85
31 104-2 81
34 104-2 47
35 104-2 74
Thanks for any help in advance.
 
Regards,
Eric


Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
<Prev in Thread] Current Thread [Next in Thread>