Hi Peter, thank you for helping. The thing is don't want to it replace it with the last value but with the next value ----- Anna Lippel -- View this message in context: http://n4.nabble.com/Error-on-using-lag-function-tp1399935p1401319.html Sent from the R help mailing list archive at Nabble.com.