[R] Speeding things up

Benjamin Dickgiesser dickgiesser at gmail.com
Mon Jan 8 11:00:30 CET 2007


Hi,

is it possible to do this operation faster? I am going over 35k data
entries and this takes quite some time.

	for(cnt in 2:length(sdata$date))
	{

		if(sdata$value[cnt] < sdata$value[cnt - 1])	{
			sdata$ddtd[cnt] <- sdata$ddtd[cnt - 1] + sdata$value[cnt - 1] -
sdata$value[cnt]
		}
		else sdata$ddtd[cnt] <- 0
	
	}
	return(sdata)

Thank you,
Benjamin



More information about the R-help mailing list