Skip to content
Prev 257162 / 398506 Next

Deleting the last value of a vector

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: