
Hello,


How can I apply a function on a vector that refers to actual (n) and previous elements in the vector (e.g. n-1)?


For example:
I would like to calculate the sum of (n-1) + n for each element of a vector and get a vector as a result. 


Besides others I tried this:


v<-c(3,6,8,1,1,3,9,5,6,3)
for (i in 1:NROW(v)){a[i]<-a[i-1]+a[i]}


I would like to get this result:
9,14,9,2,4,12,14,11,9


I would greatly appreciate your help!
Marianne 		 	   		  
	[[alternative HTML version deleted]]

