I have a simulation dataset with 500 replicates - each replicate contains 300 ids. When rep = 1, id ranges from 1-300; when rep = 2, id again ranges from 1-300 and so on.
I want to get the following: when rep = 1: id 1-300; when rep = 2: id 301-600 and so on. This can be easily done using an if-else statement if number of replicates is relatively small - like the following code does the job for four replicates:
d1 <- mutate(d1, ID = ifelse(rep==1, id,
ifelse(rep==2, id+300,
ifelse(rep==3, id+600, id+900))))
But how should I address this when I have 500 replicates? So essentially my question is: how should I code - for every unit increase in replicate column, the id column will increase by 300? I have attached the result for 4 replicates (the result of the above code).
Here is a snapshot of the data: replicate 1 replicate 4
I would use
repto identify theid, like: