Message-ID: <43909BF7.8000501@ozemail.com.au>
Date: 2005-12-02T19:09:43Z
From: Jim Lemon
Subject: values in between
In-Reply-To: <003601c5f6e0$57fa5d20$733dd080@Victor1>
Eric C. Jennings wrote:
> To start with, pardon my mistake regarding "two vectors"
>
> Yes I want all values (to two decimal digits if I can) between each of
> the values given in the vector.
> meaning I'm really try to do something like this:
> y<- c(0.4 : 0.0 : 0.2 : -0.2 : 0.6 : 0.2 : 0.0 : 0.0 : 0.4 : 0.4 : 0.2)
> which of course does not work. (But on this point, something like m<-
> c(0.2:-0.6) doesn't work either.
>
Hi Eric,
Okay, what you probably want is:
seq(0.4,0.0,by=0.01*sign(0.0-0.4))
...
This can be worked into the function that I posted, but it's getting a
bit tricky to make it general. What you want to do is to "walk" through
the values creating a sequence between each one with the above call.
in.betweens<-function(x,increment) {
lenx<-length(x)
newx<-x[1]
for(i in 1:(lenx-1))
newx<-c(newx,seq(x[i],x[i+1],by=increment*sign(x[i+1]-x[i]))[-1])
return(zapsmall(newx))
}
Jim