ChrM - 11 days ago 7

R Question

I have a data Frame of annual values that Looks something like this:

`Time Value`

01/2000-12/2000 123

01/2001-12/2001 126

01/2002-12/2002 129

...

01/2040-12/2040 223

I would like to Calculate the mean for certain parts of the time series (e.g. 2010-2015; 2015-2020; etc.)

Can anyone tell me how to do it?

Answer

```
# first extract the year
df$year <- as.numeric(sub(".*\\/", "", df$Time))
# then a simple mean() does the work for you!
mean(df$Value[df$year >= 2000 & df$year <= 2005])
```