How to select consecutive measurement cycles

Viewed 24

I am working with a dataset that contains variables measured from permanent plots. These plots are continuously remeasured every couple of years. The data sort of looks like the table at the bottom. I used the following code to separate the dataset to slice the initial measurement at t1. Now, I want to slice t2 which is the remeasurement that is one step greater than the minimum_Cycle or minimum_Measured_year. This is particularly a problem for plots that have more than two remeasurements (num_obs > 2) and the measured_year intervals and cycle intervals are different. I would really appreciate the help. I have stuck on this for quite sometime now.

df_Time1 <- df %>% group_by(State, County, Plot) %>%  slice(which.min(Cycle))
State County Plot Measured_year basal_area tph Cycle num_obs
1     1      1    2006          10         10  8     2
2     1      2    2002          20         20  7     3
1     1      1    2009          30         30  9     2
2     1      1    2005          40         40  6     3
2     1      1    2010          50         50  8     3
2     1      2    2013          60         60  10    2
2     1      2    2021          70         70  12    3 
2     1      1    2019          80         80  13    3
1 Answers

Create a t variable for yourself based on the Cycle order:

df_Time1 %>%
  group_by(State, County, Plot) %>%
  mutate(t = order(Cycle))

You can then filter on t == 1 or t == 2, etc.

Related