Skip to content
Prev 59626 / 398502 Next

sorting without order

Hi Marc,

continuing on Prof. Dalgaard's proposal, you could use:

ix <- unlist(split(seq(along=v), v), use.names=FALSE)

but even with this, `sort()' seems faster if you are interseted only 
in grouping:

v <- sample(1:25000, 50000, TRUE)
######
system.time(ix <- do.call("c",split(seq(along=v),v)), gcFirst=TRUE)
[1] 0.13 0.00 0.13   NA   NA

system.time(ix <- unlist(split(seq(along=v), v), use.names=FALSE), 
gcFirst=TRUE)
[1] 0.06 0.00 0.07   NA   NA

system.time(x <- sort(v), gcFirst=TRUE)
[1] 0.01 0.00 0.02   NA   NA


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm



----- Original Message ----- 
From: "Marc Mamin" <M.Mamin at intershop.de>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, November 23, 2004 10:58 AM
Subject: [R] sorting without order