Hi I've a dataset with record A = 100,200,300,400... There will be a parameter n. say n=10 means i have add 10% of previous value to the current row current_Val New_value 100 100 200 210 (200+10) 300 330( 300 +20+10) 400 460 (400+30+20+10) I'm using a loop But i want takes a long time. Please help ----- Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/getting-the-value-from-previous-row-tp4554761p4554761.html Sent from the R help mailing list archive at Nabble.com.
Le vendredi 13 avril 2012 ? 06:09 -0700, arunkumar1111 a ?crit :> Hi > > I've a dataset with record A = 100,200,300,400... > > There will be a parameter n. say n=10 means i have add 10% of previous > value to the current row > > current_Val New_value > 100 100 > 200 210 (200+10) > 300 330( 300 +20+10) > 400 460 (400+30+20+10) > > I'm using a loop > But i want takes a long time. Please helpOne solution is: A <- 1:4 * 100 A + cumsum(c(0, A[-length(A)]) * 0.1) [1] 100 210 330 460 Hope this helps
Thanks it helped a lot ----- Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/getting-the-value-from-previous-row-tp4554761p4560577.html Sent from the R help mailing list archive at Nabble.com.