[EMAIL PROTECTED]

>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

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to