I have a dataframe of transect data, such that for each transect, there are species codes and for each species, there is a count associated. I'm trying to calculate a proportion of transects that ID a particular species by separating the data frame into each transect. How can I take a vector of repeating chunks of numbers, separate it by chunks of same values, and get the indices?
Example:
x <- c(1, 2, 1, 2, 3, 1)
y <- c(3, 2, 3, 3, 2, 3)
Transects <- rep(x, y)
I want it to output chunks like these
c(1, 1, 1)
c(2, 2)
c(1, 1, 1)
c(2, 2, 2)
c(3, 3)
c(1, 1, 1)
or more importantly, the associated indices, which would give me
c(1, 2, 3)
c(4, 5)
c(6, 7, 8)
c(9, 10, 11)
c(12, 13)
c(14, 15, 16)
I don't even know what functions to try, because I don't know what indices to separate the vector at, nor can I separate by simple value because there are chunks of the same values and I don't want those mixed together since they're different transects. Any help is appreciated, I wouldn't even know how to go about building a function that could do this.