[R] avoiding timconsuming for loop renaming identifiers
François Pinard
pinard at iro.umontreal.ca
Sat Jul 21 04:03:01 CEST 2007
[toby909 at gmail.com]
>I was wondering if I can avoid a time-consuming for loop on my 600000
>obs dataset.
>school_id y
>8 9.87
>8 8.89
>8 7.89
>8 8.88
>20 6.78
>20 9.99
>20 8.79
>31 10.1
>31 11
>There are, say, 143 different schools in this 600000 obs dataset.
>I need to thave sequential identifiers, 1,2,3,4,5,...,143.
Hello, Toby. Maybe:
dta$id <- cumsum(c(1, diff(dta$school_id) != 0))
--
François Pinard http://pinard.progiciels-bpi.ca
More information about the R-help
mailing list