Average of first and last variable : <p><a href="https://i.stack.imgur.com/TEkoN.png" rel="nofollow noreferrer">Sample Data</a></p>

<p>The highlighted color is the first and the last of each customer ID how do I use R code to do this and below is the answer expected</p>

<p><a href="https://i.stack.imgur.com/quZLQ.png" rel="nofollow noreferrer">Answer expected</a></p>
