[R] Create counter variable for subsets without a loop

Bart Joosen bartjoosen at hotmail.com
Tue May 18 12:22:05 CEST 2010


Solved it another way, without apply:


data2 <- data[order(data$state.region,-data$Population),]
cx <- as.numeric(data2$state.region)
data2$rank <- cumsum(rep(1,length(cx)))-match(cx,cx) + 1
all.equal(data2==data)


Bart
-- 
View this message in context: http://r.789695.n4.nabble.com/Create-counter-variable-for-subsets-without-a-loop-tp2220663p2221052.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list