Hoping I can get this point across. I'm looking to calculate the slope of certain data.
I have a dataset containing 16,725 measurements across 1994 days. Each measurement begins when the header (column 1) reads 21, but the length varies each day. For my variable of interest (column 2), I'm looking to calculate the slope under certain conditions. For example, in the first measurement period (1:9), I am interested in the slope before there is considerable change (increase) in the data (this would be points 1:5). For the second measurements period (10:20), this would be points 1:4.
I'm not sure how I would go about doing this. I thought to incorporate diff() somehow to analyze the difference between two points, and find what values to calculate the slope for. I'm also curious if it would be difficult to do given the current formatting of the data, or if I could create a loop, restarting/recalculating everytime column 1 reads 21. As I mentioned, there are 1994 days of data, so ideally, in the end, I would have a slope value for my data of interest, 1994 points long (1 each day).