the below dataset is just top 8 rows of 100 rows dataset.
>a
group marks upd
2 C 3 up
3 C 4 down
6 C 7 up
1 T 2 up
4 T 5 up
5 T 6 down
7 T 1 middle
8 T 0 down
I 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