I have a relatively large dataset (16,000+ x ~31). In other words, it's large enough that I don't want to manipulate it line by line in Excel. The data is in this form:
block site day X1 X2
1 1 1 0.4 5.1
1 1 2 0.8 1.1
1 1 3 1.1 4.2
1 2 1 ... ...
1 2 2
1 2 3
2 3 1
2 3 2
2 3 3
2 4 1
2 4 2
2 4 3
As you can see, the site count is continuous but I would like a column where the site number resets with each block. For example, I would like something like this below:
block site day X1 X2 site2
1 1 1 0.4 5.1 1
1 1 2 0.8 1.1 1
1 1 3 1.1 4.2 1
1 2 1 ... ... 2
1 2 2 2
1 2 3 2
2 3 1 1
2 3 2 1
2 3 3 1
2 4 1 2
2 4 2 2
2 4 3 2
I was thinking about using the R function rle but am not sure if it will work because of complications with day. Otherwise, I would try something like:
Data$site2 <- sequence(rle(Data$block)$lengths)
Does anyone have any suggestions for adding a column counting (sequence) the number of sites within each block? If it helps, there are the same number of days (263) recorded for each site but there are a different number of sites per block.