I want to add ID variable in this data. If receipt_ids are sequenced numbers, then those have same IDs.
CUST_NO_ID receipt_id dollar 12 29
This does it
id <- 1 for(row in 1:nrow(data)){ if(row == 1){ dif <- 1 }else{ dif <- data[row,'receipt_id'] - data[row-1,'receipt_id'] } if(dif != 1){ id = id + 1 } data[row,'ID'] = id }