Re: [R] recode the ID with sequential order of a dataset

2014-06-04 Thread arun
Hi York, Using "dat" (assuming that the data is ordered by "ID") dat$NEWID <- cumsum(c(TRUE,with(dat, ID[-1]!= ID[-length(ID)]))) A.K. Hi arun, Thanks for your reply. I think you misunderstood my question, for the new ID, I would like to have the following pattern, ID TIME NEWID 1254 0  

Re: [R] recode the ID with sequential order of a dataset

2014-05-23 Thread arun
Hi, May be this helps: #if the data is ordered for the "TIME" column as in the example dat <- read.table(text="ID TIME 1254 0 1254 1 1254 3 1254 5 1254 14 3236 0 3236 36 3236 93 1598 0 1598 0.5 1598 1 1598 2 1598 3 1598 12 1598 36 1598 75 1598 95 1598 120",sep="",header=TRUE)  dat$NewID <- with(