I am assuming that Dn has been sorted.
whichismin<-function(x){return(which(x==min(x)))}
# function to return the location where the minimun occurs
m<-length(table(Dn)) # number of days
tapply(R1,Dn,whichismin)+cumsum(c(0,table(Dn)[-m]))
This can accomodate the ties between the minimum values
different days, but cannot deal with the multiple minimums
within each day.
Good luck,
jingshan
On Tue, 17 Jun 2003, Janusz Borkowski wrote:
>
> Dear S+ users,
> I have a data frame in which the first column indicates the day number, the
> second column observation number and the third results of observations. It
> may look like:
> Dn On R1
> 1 1 3
> 1 2 4
> 1 3 5
> 2 4 6
> 2 5 7
> 2 6 8
> To find minimum value of R1 for each day is easy:
> min.valR1<-Tapply(R1,Dn,min)
> but how can I get not only the vector of minimum values, but also a vector of
> observation numbers for which the minimum occurred
> I am using S+ 4.5 for Windows.
> I will appreciate any advice.
> Janusz Borkowski
>
>
>
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|