[R] Replace last element in a vector - elegant solution?

2010-07-29 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi I have to replace the last element of a vector with 0, but the length of x is not known at coding time. So I do the following: x - 1:10 x x[length(x)] - 0 x it is working nicely, but I am wondering: is there a more elegant solution( like

Re: [R] Replace last element in a vector - elegant solution?

2010-07-29 Thread Henrique Dallazuanna
Another way: x - replace(x, length(x), 0) On Thu, Jul 29, 2010 at 8:12 AM, Rainer M Krug r.m.k...@gmail.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi I have to replace the last element of a vector with 0, but the length of x is not known at coding time. So I do the

Re: [R] Replace last element in a vector - elegant solution?

2010-07-29 Thread Wu Gong
Hi, The function head also works. x - 1:10 head(x,-1) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Replace-last-element-in-a-vector-elegant-solution-tp2306315p2306471.html Sent from the R help mailing list archive at Nabble.com.