Dear All,

I am trying to capture the first and last values of number of shares for companies. The data looks like:

```
COMPANY_NUMBER YEAR_END_DATE NUMBER_OF_YEARS NUMBER_OF_SHARES FIRST_LAST_SHARES
#0070837 31/12/2011 6 68.03 0
#0070837 31/12/2012 6 54.05 0
#0070837 31/12/2013 6 24.94 0
#0070837 31/12/2014 6 20.58 0
#0070837 31/12/2015 6 16.37 0
#0070837 31/12/2016 6 22.68 0
1000403 31/12/2007 4 7.7 0
1000403 31/12/2008 4 6.2 0
1000403 31/12/2009 4 4.89 0
1000403 31/12/2010 4 4.55 0
1000608 31/12/2007 3 285.71 0
1000608 31/12/2008 3 454.55 0
1000608 31/12/2009 3 555.56 0
```

I want to capture the number of shares for the first and the last year only. To do this I have a loop which increments by number of years. Number of years is at least three.

The code I have written is

```
for(i in seq(from = 1, to = 50, by = (PLC2_Not_Null2$NUMBER_OF_YEARS[i]-1)))
{
for (j in 1:PLC2_Not_Null2$NUMBER_OF_YEARS[i]){
if (j ==1 )
{PLC2_Not_Null2$FIRST_LAST_SHARES[j]=PLC2_Not_Null2$NUMBER_OF_SHARES[j]
} else if (PLC2_Not_Null2$NUMBER_OF_YEARS[j] == PLC2_Not_Null2$NUMBER_OF_YEARS[i] )
{PLC2_Not_Null2$PLC2_Not_Null2$FIRST_LAST_SHARES[i]=PLC2_Not_Null2$NUMBER_OF_SHARES[i]
} else {PLC2_Not_Null2$first_last_shares[i] = 0}
}
}
```

The error I get is

```
Error in seq.default(from = 1, to = 50, by = (PLC2_Not_Null2$NUMBER_OF_YEARS[i] - :
'by' must be of length 1
```

by value will never be zero so I don't understand what have I done wrong?

Thanks in advance fr your help.

My comfort with R is growing thanks to all of you.

Kind regards

Ahson