title: How can I remove a set of specific data, based on a condition, from a large dataset in R?
body: <p>I have this dataset which includes all the sales for a company in a given year (company code = gvkey, year = fyearq, sales = saley), its sales growth rates(growth_rate_adjusted) (in regards to the past year) and the volatility of its growth rates. However, there are some outliers in this data set for certain years. In this case, I want to remove all rows for the year 1995 that have higher volatility than 3.0.</p>
  
  <p>I have tried using ddplyr to filter it out in the following way</p>
  
  <pre><code>rs &lt;-rs%&gt;%
    filter(!fyearq == 1995 &amp; !volatility &gt; 3.0) %&gt;%
    ungroup()
  </code></pre>
  
  <p>But that excludes all volatility above 4 for all years and excludes 1995 entirely from the dataset, which isn't my goal.  </p>
  
  <p>I would appreciate if someone could tell me how I can condition it to be only the volatility above 3.0 for the year 1995 specifically. I am unfortunately fairly new to R.</p>
  
  <p>A sample with the data ordered by year for 1994 and 1995 (there will be some NA's, but they are ok) to make it reproducible:</p>
  
  <pre><code>structure(list(gvkey = c(65089L, 65090L, 65091L, 65094L, 65095L, 
  65298L, 65351L, 65499L, 66430L, 66591L, 66624L, 109584L, 119053L, 
  143972L, 145348L, 277918L, 1004L, 1009L, 1010L, 1011L, 1013L, 
  1017L, 1019L, 1021L, 1025L, 1033L, 1034L, 1037L, 1038L, 1043L, 
  1045L, 1048L, 1050L, 1055L, 1056L, 1072L, 1073L, 1075L, 1076L, 
  1078L, 1082L, 1084L, 1086L, 1090L, 1094L, 1095L, 1097L, 1098L, 
  1099L, 1104L, 1107L, 1108L, 1109L, 1111L), fyearq = c(1994L, 
  1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 
  1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1995L, 1995L, 1995L, 
  1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 
  1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 
  1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 
  1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L), growth_rate_adjusted = c(8.96928631198866, 
  8.4280138706961, 9.02704614077282, 8.10147860671897, 7.85740916384215, 
  10.7523572462577, 0.0325017896704669, 0.285143311711521, -0.0215766088784792, 
  7.5140205008648, 10.4833287736384, 1.73691297130171, 0.117237940329646, 
  1.34207225611898, 8.38865848733786, NA, 11.217767632108, -0.304963611388244, 
  8.90548855887399, -0.465405529093955, 0.308162761266, -0.428463261697025, 
  9.71621276929561, -0.272514090039389, 0.365258326126507, -0.835436753370402, 
  10.6675419276932, 21.8645191343365, 0.172555503849585, -0.0528834362682823, 
  9.77177091825209, -0.0617758053830246, 7.26998471225084, 10.2427038986383, 
  0.174166169584557, 11.7224789811471, 5.10323576237965, -0.0390433072454226, 
  8.410713700002, 10.0433658114349, 8.56357182841634, 13.2022040407414, 
  11.9928308829399, 11.6432049346405, 0.117529642161838, 9.53135348756221, 
  9.58048755435235, 0.0758862747892137, 0.0654783197588846, 9.49577594725737, 
  10.4061554746601, -0.454122878475859, 12.2471344335624, 37.1728040342351
  ), volatility = c(2.55192643294808, 2.39434025265926, 2.56344451051799, 
  2.30624765181967, 2.23928130844332, 3.04354720436549, NA, 0.402804266987728, 
  0.358552136097001, 2.13611997423426, 2.98090959393336, NA, 0.0847119569693743, 
  NA, 2.37661435221257, NA, 3.18081892321314, NA, 2.52968180517002, 
  NA, 0.429862168272561, NA, 2.76287646243831, 0.454406152459777, 
  NA, NA, 3.0077233808187, 6.17293600484418, 0.304536845392376, 
  0.0411853414230726, 2.76986690678473, 0.157817595412998, 1.99372992450495, 
  NA, 0.293215830307968, 3.24928278487391, NA, 0.342934649585831, 
  2.35498186010912, 2.84022723248247, 2.40517143665036, 3.13067695078128, 
  NA, NA, 0.326138274385994, 2.70848653980122, 2.74871785774601, 
  NA, 0.299889508129728, 2.71608606652565, 2.94982624906776, NA, 
  3.47847130692363, 10.490117417769)), row.names = c(NA, -54L), class = c("tbl_df", 
  "tbl", "data.frame"))
  </code></pre>