Skip to content
Prev 320153 / 398506 Next

Getting a vector result from a computed index

Hi,
On Mar 22, 2013, at 11:09 PM, Justin Long wrote:

            
I'm not very clear on what you are trying in the above code block, but comparing neighbor values is very easy.

n <- 10
x <- floor(runif(n, min = 1, max = 10))
dx <- diff(x)
[1] 6 3 2 4 8 8 2 2 4 2
[1] -3 -1  2  4  0 -6  0  2 -2

Is that what you are aiming for?

Also, 'next' is a reserved word in R, that might be why an error is raised.  See ?next  

Even if you could get past that, you'll get unexpected results if the index [i-1] falls to less than 1 or the index [i+1] rises to greater than the length of results.
numeric(0)
[1] NA

Cheers,
Ben



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org