Skip to content
Prev 325748 / 398503 Next

How to define desired numbers to a vector based on the present numbers

I suspect the OP may want

rep(1:length(unique(x)), rle(x[order(x)])$lengths)[order(order(x))]

to allow for variable numbers of unique values.

Clint

Clint Bowman			INTERNET:	clint at ecy.wa.gov
Air Quality Modeler		INTERNET:	clint at math.utah.edu
Department of Ecology		VOICE:		(360) 407-6815
PO Box 47600			FAX:		(360) 407-7534
Olympia, WA 98504-7600

         USPS:           PO Box 47600, Olympia, WA 98504-7600
         Parcels:        300 Desmond Drive, Lacey, WA 98503-1274
On Fri, 21 Jun 2013, Rui Barradas wrote: