[R] Can you have a by variable in Lag function as in SAS

ramoss ramine.mossadegh at finra.org
Thu Nov 15 20:55:50 CET 2012


Hello,

I want to use lag on a time variable but I have to take date into
consideration ie I don't want days to overlap ie: 
I don't want my first time of today to match my last time of yeterday.

In SAS I would use :

data x;
  set y;
  by date tim;
  previous=lag(tim);
  if first.date then
     do;
	    previous=.;
     end;
run;

How can I do something similar in R?  I can't find any examples anywhere.

Thank you all for your help.



--
View this message in context: http://r.789695.n4.nabble.com/Can-you-have-a-by-variable-in-Lag-function-as-in-SAS-tp4649647.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list