Why not use 'head'
> head(1:10, -1)
[1] 1 2 3 4 5 6 7 8 9
> head(1, -1)
numeric(0)
> head(integer(0), -1)
integer(0)
On Mon, Apr 18, 2011 at 8:13 AM, Kenn Konstabel wrote:
> On Mon, Apr 18, 2011 at 4:14 AM, helin_susam wrote:
>> if you have a vector like as follows;
>>
>> r=c(1,2,3,4,5)
>>
>>
On Mon, Apr 18, 2011 at 4:14 AM, helin_susam wrote:
> if you have a vector like as follows;
>
> r=c(1,2,3,4,5)
>
> then use
>
> r2=r[1:length(r)-1]
Umm ... this works and gives the intended answer but does so in an ugly way --
1:length(r)-1 is equivalent to (1:length(r))-1 or 0:(length(r)-1) --
This is unlikely to be the kind of operation where speed is essential,
but nevertheless on my build of 2.14.0 (with byte compiled base packages):
stopifnot(getRversion()>= "2.14")
library("compiler")
f1<- function (x, n) head(x, length(x) - n)# suggested by baptiste auguie
f2<- function (x, n)
if you have a vector like as follows;
r=c(1,2,3,4,5)
then use
r2=r[1:length(r)-1]
--
View this message in context:
http://r.789695.n4.nabble.com/Deleting-the-last-value-of-a-vector-tp3456363p3456388.html
Sent from the R help mailing list archive at Nabble.com.
___
Hi
r-help-boun...@r-project.org napsal dne 18.04.2011 04:51:20:
> Or perhaps even more parsimoniously (by a couple of characters) -
>
> r <- c(1, 2, 3, 4, 5)
> r2<-r[-length(r)]
Maybe even shorter
head(x,-1)
Regards
Petr
>
> Min-Han
>
> On Sun, Apr 17, 2011 at 10:23 PM, Daisy Englert Duur
Or perhaps even more parsimoniously (by a couple of characters) -
r <- c(1, 2, 3, 4, 5)
r2<-r[-length(r)]
Min-Han
On Sun, Apr 17, 2011 at 10:23 PM, Daisy Englert Duursma <
daisy.duur...@gmail.com> wrote:
> A easier solution:
>
> r <- c(1, 2, 3, 4, 5)
> r2<-r[1:length(r)-1]
>
>
>
>
> On Mon, Apr
A easier solution:
r <- c(1, 2, 3, 4, 5)
r2<-r[1:length(r)-1]
On Mon, Apr 18, 2011 at 10:51 AM, empyrean 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
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
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 mis
9 matches
Mail list logo