I am trying to do something that I am sure is easy, but I don't even know what to search for properly to find the soultion.
I have a long time series of data. One column indicates state, which has a value of 0, 1, 2 or -1. I want to extract and work on the data where state = 2. It is no problem to extract all this data; what I want to do is treat each period where state=2 individually.That is, I want to go through the data, and where state=2, do some analysis (eg a linear fit to the initial period on other variables associated with this time period), then move on to the next instance where state=2 and repeat this analysis. Or, extract each period of data to its own dataframe and do the analysis (but this will create hundereds of small dataframes).
I can't even work out how to identify the start points (ie where i=2 and i-1=1).
Any pointers to the commands or packages that I should be looking at would be greatly appreciated.