a********a 发帖数: 346 | 1 The sas data set like:
id aa
1 2
1 2
1 4
1 5
1 5
1 5
2 3
2 3
2 3
2 10
2 10
2 15
....
How do you get the smallest aa out in each id? I also want to get all the
smallest aa even aa has several same values.
i.e. I want to get
id aa
1 2
1 2
2 3
2 3
2 3
Thanks |
f********t 发帖数: 117 | 2 select t.* from table t, (select id, min(aa) as aamin
from table
group by id ) tmin
where t.aa = tmin.aamin and t.id = tmin.id order by t.id |
a********a 发帖数: 346 | 3 Thanks firstquant, I do not understand the program very well, but it works. |
a********a 发帖数: 346 | 4 Is there any idea how to do this in R?
Thanks |
f********t 发帖数: 117 | 5 Im not a R expert. I guess you have to do it sby step.
first you sort table by id, and aa asc. you loop to keep the first row for
each id.(or here you can keep the all rows with min value, then you dont
need to do anything else) then you merge table with this new table by id
and min.
发信人: acervulina (acervulina), 信区: Statistics
标 题: Re: sas help
发信站: BBS 未名空间站 (Mon May 11 10:07:07 2009)
Is there any idea how to do this in R?
Thanks |