[R] How to replicate SAS by group processing in R

ramoss ramine.mossadegh at finra.org
Wed Oct 10 20:09:44 CEST 2012


Hello,

I am trying to re-code all my programs from SAS into R.

In SAS I use the following code:

proc sort data=upper;
by tdate stock_symbol expire  strike;
run;
data upper1;
  set upper;
  by tdate stock_symbol expire  strike;
  if first.expire then output;
  rename strike=astrike;
run;

on the following data set:

tdate	stock_symbol	expiration 	strike
9/11/2012	C	                   9/16/2012	11
9/11/2012	C	                   9/16/2012	12
9/11/2012	C	                   9/16/2012	13
9/12/2012	C	                   9/16/2012	14
9/12/2012	C	                   9/16/2012	15
9/12/2012	C	                   9/16/2012	16
9/12/2012	C	                    9/16/2012	17

to get the following results:
tdate	stock_symbol	expiration 	strike
9/11/2012	C	                   9/16/2012	11
9/12/2012	C	                   9/16/2012	14

How would I replicate this kind of logic in R?
I have seen PLY & data.table packages mentioned but don't see how they would
do the job.

Thanks ahead for your help



--
View this message in context: http://r.789695.n4.nabble.com/How-to-replicate-SAS-by-group-processing-in-R-tp4645753.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list