title: How to replace a value in multiple columns based on criteria?
body: <p>I would like to replace all values <code>99</code> with <code>NA</code> for all records where <code>ART == '999'</code> only in columns <code>L1:L8</code>. I know how to do this for once column at a time, but I would like to do this more efficiently for all columns in one command.</p>
  
  <p>Sample data:</p>
  
  <pre><code>df &lt;- structure(list(KARTA = c("02C2H", "02C2H", "02C2H", "02C2H", 
  "02C2H", "02C2H", "02C2H", "02C2H", "02C2H", "02C2H", "02C2H", 
  "02C2H", "02C2H", "02C7H", "02C7H", "02C7H", "02C7H", "02C7H", 
  "02C7H", "02C7H", "02C7H", "02C7H", "02C7H", "02C7H", "02C7H"
  ), YEAR = c(1997L, 1999L, 2000L, 2001L, 2002L, 2003L, 2005L, 
  2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 1997L, 1998L, 2000L, 
  2001L, 2002L, 2003L, 2004L, 2006L, 2008L, 2009L, 2010L, 2011L
  ), ART = c("999", "999", "100", "100", "100", "999", "999", "999", 
  "999", "999", "999", "999", "999", "999", "999", "999", "999", 
  "999", "999", "999", "999", "999", "999", "999", "999"), L1 = c(99, 
  99, 99, 99, 99, 10, 10, 10, 10, 10, 10, 10, 10, 99, 99, 99, 99, 
  99, 10, 10, 10, 10, 10, 10, 10), L2 = c(99, 99, 99, 99, 99, 10, 
  10, 10, 10, 10, 10, 10, 10, 99, 99, 99, 99, 99, 10, 9, 10, 10, 
  10, 10, 10), L3 = c(99, 99, 99, 99, 99, 7, 10, 10, 10, 10, 10, 
  10, 10, 99, 99, 99, 99, 99, 10, 10, 10, 10, 10, 10, 10), L4 = c(99, 
  99, 99, 99, 99, 10, 10, 10, 10, 10, 10, 10, 10, 99, 99, 99, 99, 
  99, 10, 10, 8, 7, 7, 10, 8), L5 = c(99, 99, 99, 99, 99, 5, 8, 
  10, 10, 10, 10, 10, 10, 99, NA, 99, 99, 99, 10, 10, 7, 7, 0, 
  10, 8), L6 = c(99, 99, 99, 99, 99, 8, 10, 10, 10, 10, 10, 10, 
  10, 99, 99, 99, 99, 99, 10, 9, 10, 10, 10, 10, 10), L7 = c(99, 
  99, 99, 99, 99, 10, 10, 10, 10, 10, 10, 8, 10, 99, 99, 99, 99, 
  99, 10, 10, 10, 10, 10, 10, 10), L8 = c(99, 99, 99, 99, 99, 10, 
  10, 10, 10, 10, 10, 10, 10, 99, 99, 99, 99, 99, 10, 10, 6, 10, 
  10, 10, 10)), .Names = c("KARTA", "YEAR", "ART", "L1", "L2", 
  "L3", "L4", "L5", "L6", "L7", "L8"), row.names = c(161008L, 161009L, 
  161010L, 161011L, 161012L, 87055L, 106223L, 128072L, 160909L, 
  172583L, 208774L, 45L, 227972L, 161013L, 161014L, 161015L, 161016L, 
  161017L, 71813L, 89034L, 139633L, 181266L, 208838L, 97L, 225989L
  ), class = "data.frame")
  </code></pre>
  
  <p>Example of how to replace values in a single column ('L1')</p>
  
  <pre><code>df[which(df$ART == '999' &amp; df$L1 == '99'), ] &lt;- NA
  </code></pre>