Hi, I am missing something obvious.
Need to create vector as: (0, i-1 + TheoP(i) - TheoP(i-1), repeat....) Where i is the index position in the vector and i[1] is always 0. Found myself having to use a For Loop because I could not get sapply working. Any suggestions ? delta <- function(x) { start = index[x] end = index[x+1] - 1 iTheo = start:end len = length(iTheo) theoP = as.numeric(TheoBA$Bid[iTheo]) d = vector(mode = "numeric", length= len) d[1] = 0 if (len>1) for (i in 2:len) { d[i] = d[i-1] + theoP[i] - theoP[i-1] } return(d) } Thanks, Chris -- View this message in context: http://r.789695.n4.nabble.com/Replace-for-loop-when-vector-calling-itself-tp3338383p3338383.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.