title: How to get the second to last element in a Vector in R
body: <p>I am trying to get the second to last element of a Vector into another vector. For an example see this data set</p>
  
  <p>Vector A</p>
  
  <pre><code>7.31 15.54  9.79  4.24  9.01  6.26 12.05  5.16 11.13  7.69  6.42 13.65 11.17 11.04  6.80  7.15 11.52 10.14 10.07 8.30
  </code></pre>
  
  <p>I want to Create a</p>
  
  <p>Vector B</p>
  
  <pre><code>  15.54  9.79  4.24  9.01  6.26 12.05  5.16 11.13  7.69  6.42 13.65 11.17 11.04  6.80  7.15 11.52 10.14 10.07 8.30
  </code></pre>
  
  <p>However I don't want to use </p>
  
  <p><code>B&lt;-A[2:20]</code> </p>
  
  <p>because with the time last element number will change(increases)</p>
  
  <pre><code>A[1:tail(A,n=1)]
  [1]  7.31 15.54  9.79  4.24  9.01  6.26 12.05  5.16
  </code></pre>
  
  <p>This gives half of the data. Just 8 elements.
  Also tried </p>
  
  <pre><code> B&lt;-A[1:last(A)]
   print(B)
  [1]  7.31 15.54  9.79  4.24  9.01  6.26 12.05  5.16
  </code></pre>
  
  <p>it gives only first few elements. why?</p>
  
  <p>the answer I expect is</p>
  
  <pre><code>15.54  9.79  4.24  9.01  6.26 12.05  5.16 11.13  7.69  6.42 13.65 11.17 11.04  6.80  7.15 11.52 10.14 10.07 8.30
  </code></pre>