shivanshu dhawan - 1 year ago 66

R Question

Answer Source

We can use `rep`

to add 53 to the `vector`

('vN2') after finding the number of observations for each year.

```
vN2 + rep(c(0, 53), tapply(vN2, cumsum(c(TRUE, diff(vN2) < 0)), FUN = length))
```

```
set.seed(24)
vN <- rep(1:53, sample(1:5, 53, replace=TRUE))
vN1 <- rep(1:53, sample(1:6, 53, replace=TRUE))
vN2 <- c(vN, vN1)
```