Skip to content
Prev 307598 / 398506 Next

How to replicate SAS by group processing in R

Hi,

here is one way using ddply (from the plyr package):

dat <- read.table(text="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",
                  header=TRUE)

library(plyr)
ddply(dat, .variables = c("tdate"), .fun = function(x) x[1, ])


Best,
Ista
On Wed, Oct 10, 2012 at 2:09 PM, ramoss <ramine.mossadegh at finra.org> wrote: