[R] Determining Index of Last Element in Vector

2010-04-25 Thread Alan Lue
Hi, Is there a way to specify the last element of a vector, similar to end in MATLAB? v[end] would be MATLAB for v(length(v)) in R. While `v(length(v))' does yield the last element, that approach fails in the following, rep(v, each=2)[-c(1,length(v))] which is meant to duplicate all

Re: [R] Determining Index of Last Element in Vector

2010-04-25 Thread Alan Lue
Sorry -- I meant `v(end)' and `v[length(v)]' in the first examples of my message. Alan On Sun, Apr 25, 2010 at 11:10 AM, Alan Lue alan@gmail.com wrote: Hi, Is there a way to specify the last element of a vector, similar to end in MATLAB?   v[end] would be MATLAB for   v(length(v)) in

Re: [R] Determining Index of Last Element in Vector

2010-04-25 Thread Jorge Ivan Velez
Hi Alan, Take a look at the following: x - 1:10 x[length(x)] [1] 10 tail(x) [1] 5 6 7 8 9 10 tail(x, 1) [1] 10 See ?tail for more information. HTH, Jorge On Sun, Apr 25, 2010 at 2:10 PM, Alan Lue wrote: Hi, Is there a way to specify the last element of a vector, similar to end

Re: [R] Determining Index of Last Element in Vector

2010-04-25 Thread Chuck Cleland
On 4/25/2010 2:10 PM, Alan Lue wrote: Hi, Is there a way to specify the last element of a vector, similar to end in MATLAB? v[end] would be MATLAB for v(length(v)) in R. While `v(length(v))' does yield the last element, that approach fails in the following, rep(v,

Re: [R] Determining Index of Last Element in Vector

2010-04-25 Thread David Winsemius
On Apr 25, 2010, at 2:22 PM, Chuck Cleland wrote: On 4/25/2010 2:10 PM, Alan Lue wrote: Hi, Is there a way to specify the last element of a vector, similar to end in MATLAB? v[end] would be MATLAB for v(length(v)) in R. While `v(length(v))' does yield the last element, that

Re: [R] Determining Index of Last Element in Vector

2010-04-25 Thread Alan Lue
Those are great solutions. Thanks so much for your help. Yours, Alan On Sun, Apr 25, 2010 at 11:43 AM, David Winsemius dwinsem...@comcast.net wrote: On Apr 25, 2010, at 2:22 PM, Chuck Cleland wrote: On 4/25/2010 2:10 PM, Alan Lue wrote: Hi, Is there a way to specify the last element of