the below dataset is just top 8 rows of 100 rows dataset.>a  group marks    upd2     C     3     up3     C     4   down6     C     7     up1     T     2     up4     T     5     up5     T     6   down7     T     1 middle8     T     0   downI used unique_groups=unique(a$group) to get a list of unique group names to be sent into a function. Now, I need a function that gives a subset of this dataset where it takes each group from unique_groups and checks if 'upd' is in ('down','middle') and gives me a dataset having only those records having upd ('down','middle') of that respective group.I tried to use do.call function to get the dataset that I want as-do.call(rbind,sapply(unique_groups,FUN=function(y)  {  h=a[a$group==x & a$upd %in% c('down','middle'),]  h}, simplify=F))I wasnt getting the dataset that I want and it was giving this warning message:In ==.default(a$group, x) :  longer object length is not a multiple of shorter object length
sub-setting based on categorical variable in R
r