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 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 a vec

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 approa

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,

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, simila

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 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. > Whil

[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