0
votes

I'm looking for some guidance on applying the filter() function.

Below is an example of my data, I want to filter out investors with a 'treatment' year of 2006, 2007 and 2008.

An example of the data is below:

investor dealyear dealcounts treatment other characteristics
123 IM 2003 5 2006 various
123 IM 2004 5 2006 various
123 IM 2005 5 2006 various
123 IM 2006 5 2006 various
123 IM 2007 5 2006 various
21 Invest 2002 5 2008 various
21 Invest 2003 5 2008 various
21 Invest 2004 5 2008 various
21 Invest 2005 5 2008 various
21 Invest 2006 5 2008 various
21 Invest 2007 5 2008 various
21 Invest 2008 5 2008 various

Thanks for any tips!

1

1 Answers

1
votes

Do you mean something like this ?

result<- df %>% filter(!investor %in% unique(investor[treatment %in% 2006:2008]))

In base R -

result <- subset(df, !investor %in% unique(investor[treatment %in% 2006:2008]))