Another way to do this is to realize that what is wanted is essentially
a join (in the relational database sense) of dat and the unique rows
of dat.  We use merge to perform the join in the following.  The first
few lines set up the data for merge and the last one unscrambles it
since merge does not preserve ordering.  Note that apply is nowhere
used, suggesting that this solution may have adequate speed.

u <- unique(dat)
dat0 <- cbind( dat, seq(nrow(dat)) )
u0 <- cbind( u, seq(nrow(u)) )
by.arg <- c( rep(T,ncol(dat)), F )
dat.mrg <- merge( dat0,u0, by.x=by.arg, by.y=by.arg, sort=F )
keys <- dat.mrg[,ncol(dat.mrg)][order(dat.mrg[,ncol(dat.mrg)-1])]

First, u becomes the unique rows of dat.
The next two lines append a column of sequence numbers to dat and to u .
The 4th & 5th lines merge dat0 and u0 on all cols but the seq numbers.
At this point the last two columns of dat.mrg contain the sequence 
number of the original data frame, dat, and the corresponding sequence 
number of u.   
However, the rows may be scrambled relative to the original ordering 
in dat since merge does not preserve order so resort to get keys.


_____________________________________________________________

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

