Hi,

I'm a newbie when it comes to R, and I'm trying to figure out how to use
vectorization as opposed to for loops.  In particular, how can I create a
function that is applied on each element of a row, but can access previous
elements relative to that element?

My problem: I want to calculate something like x[i] = x[i] / x[i - 1] for
each element of a vector x:

ex.

x <- data.frame(a = c(1:10))

# incorrect
foo = function(y) {

y[n] <- y[n] / y[n-1]

}

div <- lapply(x, foo)

Any help would be greatly appreciated.

Regards,
-Amol Shelat

	[[alternative HTML version deleted]]

