Re: [R] Deleting the last value of a vector

From: baptiste auguie <baptiste.auguie_at_googlemail.com>
Date: Mon, 18 Apr 2011 13:28:22 +1200

Hi,

Try this,

snip = function(x, n=1) {         

rand = sample(1:3, 1)
print(paste("using algorithm #", rand))         

switch(rand,

	'1' = head(x, length(x) - n),
	'2' = x[ seq(1, length(x) - n) ],
	'3' = x[ - seq(length(x), by=-1, length=n) ])
}

snip(1:5)

HTH, but please do read the posting guide.

baptiste

On 18 April 2011 12:51, empyrean <ctross_at_ucdavis.edu> wrote:
> Hey guys,
>
> I've search a few threads about deleting a value from a vector, but no one
> has addressed this question so far.
>
> I want to delete the last value from a string of values
>
> I have:
>
> r = [ 1, 2, 3, 4, 5 ], and i want to make r2 = to [ 1, 2, 3, 4]
>
> So that r2 is just like r, except that it missing the final value.
>
> Thanks,
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Deleting-the-last-value-of-a-vector-tp3456363p3456363.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 18 Apr 2011 - 01:31:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Apr 2011 - 03:00:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive