I have a dataset that looks like this:
ID week action
1 1 TRUE
1 1 FALSE
1 2 FALSE
1 2 FALSE
1 3 FALSE
1 3 TRUE
2 1 FALSE
2 2 TRUE
2 2 FALSE
...
What I'd like to do is retain for each ID and each week within ID, one value of action, with preference to retaining a TRUE if there is one, else a FALSE.
So it would look like this when through:
ID week action
1 1 TRUE
1 2 FALSE
1 3 TRUE
2 1 FALSE
2 2 TRUE
...
I used plyr:
library(plyr)
ddply(df,.(ID,week),summarize,action=sum(action)>0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With